|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require 'rails_helper' |
| 4 | + |
| 5 | +RSpec.describe CommentPolicy do |
| 6 | + let(:user_types) { %i[learner teacher admin] } |
| 7 | + |
| 8 | + permissions :create?, :show?, :index? do |
| 9 | + let(:comment) { build_stubbed(:comment) } |
| 10 | + |
| 11 | + it 'grants access to all user types' do |
| 12 | + user_types.each do |user_type| |
| 13 | + expect(described_class).to permit(build_stubbed(user_type), comment) |
| 14 | + end |
| 15 | + end |
| 16 | + end |
| 17 | + |
| 18 | + permissions :destroy?, :update?, :edit? do |
| 19 | + let(:comment) { build_stubbed(:comment) } |
| 20 | + |
| 21 | + it 'grants access to the author' do |
| 22 | + expect(described_class).to permit(comment.user, comment) |
| 23 | + end |
| 24 | + |
| 25 | + it 'grants no access to other learners' do |
| 26 | + expect(described_class).not_to permit(build_stubbed(:learner), comment) |
| 27 | + end |
| 28 | + |
| 29 | + it 'grants no access to teachers not in study group' do |
| 30 | + expect(described_class).not_to permit(build_stubbed(:teacher), comment) |
| 31 | + end |
| 32 | + |
| 33 | + it 'grants access to teachers in study group' do |
| 34 | + comment = create(:comment) |
| 35 | + teacher = create(:teacher, study_groups: [comment.submission.study_group]) |
| 36 | + |
| 37 | + expect(described_class).to permit(teacher, comment) |
| 38 | + end |
| 39 | + |
| 40 | + it 'grants access to admins' do |
| 41 | + expect(described_class).to permit(build_stubbed(:admin), comment) |
| 42 | + end |
| 43 | + end |
| 44 | +end |
0 commit comments