Skip to content

Commit

Permalink
use Valkyrie to setup AdminSetService specs (#6240)
Browse files Browse the repository at this point in the history
makes these tests pass under both `.dassie` and `.koppie`.
  • Loading branch information
tamsin johnson authored Aug 29, 2023
1 parent d5ca3b4 commit cfa77d1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
7 changes: 7 additions & 0 deletions spec/factories/administrative_sets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
end

after(:create) do |admin_set, evaluator|
admin_set.permission_manager.edit_groups = evaluator.edit_groups
admin_set.permission_manager.edit_users = evaluator.edit_users
admin_set.permission_manager.read_users = evaluator.read_users
admin_set.permission_manager.read_groups = evaluator.read_groups

admin_set.permission_manager.acl.save

if evaluator.with_permission_template
template = Hyrax::PermissionTemplate.find_or_create_by(source_id: admin_set.id.to_s)
evaluator.access_grants.each do |grant|
Expand Down
18 changes: 9 additions & 9 deletions spec/services/hyrax/admin_set_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,32 @@
search_state_class: nil)
end
let(:service) { described_class.new(context) }
let(:user) { create(:user) }
let(:user) { FactoryBot.create(:user) }

describe "#search_results", :clean_repo do
subject { service.search_results(access) }

let!(:as1) { create(:admin_set, read_groups: ['public'], title: ['foo']) }
let!(:as2) { create(:admin_set, read_groups: ['public'], title: ['bar']) }
let!(:as3) { create(:admin_set, edit_users: [user.user_key], title: ['baz']) }
let!(:as1) { FactoryBot.valkyrie_create(:hyrax_admin_set, read_groups: ['public']) }
let!(:as2) { FactoryBot.valkyrie_create(:hyrax_admin_set, read_groups: ['public']) }
let!(:as3) { FactoryBot.valkyrie_create(:hyrax_admin_set, edit_users: [user.user_key]) }

before do
create(:collection, :public) # this should never be returned.
FactoryBot.valkyrie_create(:hyrax_collection, :public) # this should never be returned.
end

context "with read access" do
let(:access) { :read }

it "returns three admin sets" do
expect(subject.map(&:id)).to match_array [as1.id, as2.id, as3.id]
expect(service.search_results(access).map(&:id))
.to contain_exactly(as1.id, as2.id, as3.id)
end
end

context "with edit access" do
let(:access) { :edit }

it "returns one admin set" do
expect(subject.map(&:id)).to match_array [as3.id]
expect(service.search_results(access).map(&:id))
.to contain_exactly(as3.id)
end
end
end
Expand Down

0 comments on commit cfa77d1

Please sign in to comment.