Files
codeocean/spec/policies/submission_policy_spec.rb
Sebastian Serth 99bd46af1a Align project files with CodeHarbor
Since both projects are developed together and by the same team, we also want to have the same code structure and utility methods available in both projects. Therefore, this commit changes many files, but without a functional change.
2023-10-11 00:18:33 +02:00

48 lines
1.6 KiB
Ruby

# frozen_string_literal: true
require 'rails_helper'
RSpec.describe SubmissionPolicy do
subject(:policy) { described_class }
permissions :create? do
it 'grants access to anyone' do
%i[admin external_user teacher].each do |factory_name|
expect(policy).to permit(create(factory_name), Submission.new)
end
end
end
%i[download_file? render_file? run? score? show? statistics? stop? test?].each do |action|
permissions(action) do
let(:exercise) { build(:math) }
let(:group_author) { build(:external_user) }
let(:other_group_author) { build(:external_user) }
it 'grants access to admins' do
expect(policy).to permit(build(:admin), Submission.new)
end
it 'grants access to authors' do
contributor = create(:external_user)
expect(policy).to permit(contributor, build(:submission, exercise:, contributor:))
end
it 'grants access to other authors of the programming group' do
contributor = build(:programming_group, exercise:, users: [group_author, other_group_author])
expect(policy).to permit(group_author, build(:submission, exercise:, contributor:))
expect(policy).to permit(other_group_author, build(:submission, exercise:, contributor:))
end
end
end
permissions :index? do
it 'grants access to admins only' do
expect(policy).to permit(build(:admin), Submission.new)
%i[external_user teacher].each do |factory_name|
expect(policy).not_to permit(create(factory_name), Submission.new)
end
end
end
end