Skip to content

Commit

Permalink
Add a test for WorksControllerBehavior override to ensure that admins…
Browse files Browse the repository at this point in the history
… get exempted from visibility restrictions
  • Loading branch information
bbpennel committed Oct 26, 2023
1 parent 04ae92d commit 69231a0
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
65 changes: 65 additions & 0 deletions spec/controllers/concerns/hyrax/works_controller_behavior_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# frozen_string_literal: true
require 'rails_helper'

RSpec.describe Hyrax::WorksControllerBehavior, type: :controller do
let(:paths) { controller.main_app }

controller(ApplicationController) do
include Hyrax::WorksControllerBehavior # rubocop:disable RSpec/DescribedClass

self.curation_concern_type = General
end

describe '#available_admin_sets' do
context 'with a logged in user' do
before { sign_in user }

context 'admin set limited to public and no embargoes' do
let(:admin_set) { Hyrax::AdminSetCreateService.find_or_create_default_admin_set }

let!(:permission_template) do
FactoryBot.create(:permission_template,
source_id: admin_set.id,
release_period: Hyrax::PermissionTemplate::RELEASE_TEXT_VALUE_NO_DELAY)
end

let!(:permission_template_access) do
FactoryBot.create(:permission_template_access,
:deposit,
permission_template: permission_template,
agent_type: 'user',
agent_id: user.user_key)
end

let!(:workflow) do
Sipity::Workflow.create(name: 'test', allows_access_grant: true, active: true,
permission_template_id: permission_template.id)
end

context 'as a regular user' do
let(:user) { FactoryBot.create(:user) }

it 'populates allowed admin sets with configured visibility restrictions' do
admin_sets = controller.available_admin_sets
options = admin_sets.select_options

expect(options).to contain_exactly(
['Default Admin Set', admin_set.id.to_s, {'data-release-no-delay'=>true, 'data-sharing'=>true}])
end
end

context 'as an admin user' do
let(:user) { FactoryBot.create(:admin) }

it 'populates allowed admin sets without visibility restrictions' do
admin_sets = controller.available_admin_sets
options = admin_sets.select_options

expect(options).to contain_exactly(
['Default Admin Set', admin_set.id.to_s, {'data-sharing'=>true}])
end
end
end
end
end
end
16 changes: 16 additions & 0 deletions spec/factories/permission_templates.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,22 @@
view_groups { nil }
end
end

factory :permission_template_access, class: Hyrax::PermissionTemplateAccess do
permission_template
trait :manage do
access { 'manage' }
end

trait :deposit do
access { 'deposit' }
end

trait :view do
access { 'view' }
end
end

# rubocop:disable Lint/ConstantDefinitionInBlock
class AccessHelper
def self.create_access(permission_template_id, agent_type, access, agent_ids)
Expand Down

0 comments on commit 69231a0

Please sign in to comment.