File tree Expand file tree Collapse file tree 2 files changed +56
-0
lines changed Expand file tree Collapse file tree 2 files changed +56
-0
lines changed Original file line number Diff line number Diff line change 1
1
# frozen_string_literal: true
2
2
3
3
class CommunitySolutionPolicy < AdminOnlyPolicy
4
+ def show?
5
+ # We don't have a show action, so no one can show a CommunitySolution directly.
6
+ no_one
7
+ end
8
+
9
+ def new?
10
+ # We don't have a destroy action, so no one can create a CommunitySolution directly.
11
+ no_one
12
+ end
13
+
14
+ def create?
15
+ # We don't have a destroy action, so no one can initialize a CommunitySolution directly.
16
+ no_one
17
+ end
18
+
4
19
def edit?
5
20
everyone
6
21
end
7
22
8
23
def update?
9
24
everyone
10
25
end
26
+
27
+ def destroy?
28
+ # We don't have a destroy action, so no one can destroy a CommunitySolution directly.
29
+ no_one
30
+ end
11
31
end
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
4
+
5
+ RSpec . describe CommunitySolutionPolicy do
6
+ subject ( :policy ) { described_class }
7
+
8
+ permissions ( :index? ) do
9
+ it 'grants access to admins only' do
10
+ expect ( policy ) . to permit ( build ( :admin ) , Consumer . new )
11
+ %i[ external_user teacher ] . each do |factory_name |
12
+ expect ( policy ) . not_to permit ( create ( factory_name ) , Consumer . new )
13
+ end
14
+ end
15
+ end
16
+
17
+ %i[ edit? update? ] . each do |action |
18
+ permissions ( action ) do
19
+ it 'grants access to anyone' do
20
+ %i[ admin external_user teacher ] . each do |factory_name |
21
+ expect ( policy ) . to permit ( create ( factory_name ) , CommunitySolution . new )
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ %i[ create? destroy? new? show? ] . each do |action |
28
+ permissions ( action ) do
29
+ it 'does not grant access to anyone' do
30
+ %i[ admin external_user teacher ] . each do |factory_name |
31
+ expect ( policy ) . not_to permit ( create ( factory_name ) , CommunitySolution . new )
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
You can’t perform that action at this time.
0 commit comments