Fix tests and slightly refactor some policies

This commit is contained in:
Sebastian Serth
2018-11-30 15:44:45 +01:00
parent 2125fb1c1d
commit 3665058435
14 changed files with 19 additions and 64 deletions

View File

@@ -23,11 +23,11 @@ describe 'Authorization' do
let(:user) { FactoryBot.create(:teacher) }
before(:each) { allow_any_instance_of(ApplicationController).to receive(:current_user).and_return(user) }
[Consumer, InternalUser].each do |model|
[Consumer, InternalUser, ExecutionEnvironment, FileType].each do |model|
expect_forbidden_path(:"new_#{model.model_name.singular}_path")
end
[ExecutionEnvironment, Exercise, FileType].each do |model|
[Exercise].each do |model|
expect_permitted_path(:"new_#{model.model_name.singular}_path")
end
end

View File

@@ -5,7 +5,7 @@ describe ExecutionEnvironmentPolicy do
let(:execution_environment) { FactoryBot.build(:ruby) }
[:create?, :index?, :new?].each do |action|
[:index?].each do |action|
permissions(action) do
it 'grants access to admins' do
expect(subject).to permit(FactoryBot.build(:admin), execution_environment)
@@ -21,7 +21,7 @@ describe ExecutionEnvironmentPolicy do
end
end
[:execute_command?, :shell?, :statistics?].each do |action|
[:execute_command?, :shell?, :statistics?, :show?].each do |action|
permissions(action) do
it 'grants access to admins' do
expect(subject).to permit(FactoryBot.build(:admin), execution_environment)
@@ -39,7 +39,7 @@ describe ExecutionEnvironmentPolicy do
end
end
[:destroy?, :edit?, :show?, :update?].each do |action|
[:destroy?, :edit?, :update?, :new?, :create?].each do |action|
permissions(action) do
it 'grants access to admins' do
expect(subject).to permit(FactoryBot.build(:admin), execution_environment)

View File

@@ -5,23 +5,7 @@ describe FileTypePolicy do
let(:file_type) { FactoryBot.build(:dot_rb) }
[:create?, :index?, :new?].each do |action|
permissions(action) do
it 'grants access to admins' do
expect(subject).to permit(FactoryBot.build(:admin), file_type)
end
it 'grants access to teachers' do
expect(subject).to permit(FactoryBot.build(:teacher), file_type)
end
it 'does not grant access to external users' do
expect(subject).not_to permit(FactoryBot.build(:external_user), file_type)
end
end
end
[:destroy?, :edit?, :show?, :update?].each do |action|
[:destroy?, :edit?, :update?, :new?, :create?, :index?, :show?].each do |action|
permissions(action) do
it 'grants access to admins' do
expect(subject).to permit(FactoryBot.build(:admin), file_type)