diff --git a/.rubocop_fixme.yml b/.rubocop_fixme.yml index a5df4bae43..1cf4f2c7a1 100644 --- a/.rubocop_fixme.yml +++ b/.rubocop_fixme.yml @@ -138,6 +138,9 @@ RSpec/AnyInstance: - 'spec/jobs/content_new_version_event_job_spec.rb' - 'spec/jobs/content_depositor_change_event_job_spec.rb' - 'spec/jobs/content_deposit_event_job_spec.rb' + - 'spec/jobs/hyrax/grant_edit_to_members_job_spec.rb' + - 'spec/jobs/hyrax/grant_read_to_members_job_spec.rb' + - 'spec/jobs/hyrax/revoke_edit_from_members_job_spec.rb' - 'spec/lib/hyrax/arkivo/actor_spec.rb' - 'spec/lib/hyrax/arkivo/create_subscription_job_spec.rb' - 'spec/presenters/hyrax/file_usage_spec.rb' diff --git a/spec/jobs/hyrax/grant_edit_job_spec.rb b/spec/jobs/hyrax/grant_edit_job_spec.rb new file mode 100644 index 0000000000..3594570ded --- /dev/null +++ b/spec/jobs/hyrax/grant_edit_job_spec.rb @@ -0,0 +1,11 @@ +RSpec.describe Hyrax::GrantEditJob do + let(:depositor) { create(:user) } + let(:file_set) { build(:file_set) } + + it 'grants a user edit access to a FileSet' do + expect(FileSet).to receive(:find).with(file_set.id).and_return(file_set) + expect(file_set).to receive(:edit_users=).with(array_including(depositor.user_key)) + expect(file_set).to receive(:save!) + described_class.perform_now(file_set.id, depositor.user_key) + end +end diff --git a/spec/jobs/hyrax/grant_edit_to_members_job_spec.rb b/spec/jobs/hyrax/grant_edit_to_members_job_spec.rb new file mode 100644 index 0000000000..581853eb0b --- /dev/null +++ b/spec/jobs/hyrax/grant_edit_to_members_job_spec.rb @@ -0,0 +1,16 @@ +RSpec.describe Hyrax::GrantEditToMembersJob do + let(:depositor) { create(:user) } + let(:work) { build(:work) } + let(:file_set_ids) { ['xyz123abc', 'abc789zyx'] } + + before do + allow_any_instance_of(described_class).to receive(:file_set_ids).with(work).and_return(file_set_ids) + end + + it 'loops over FileSet IDs, spawning a job for each' do + file_set_ids.each do |file_set_id| + expect(Hyrax::GrantEditJob).to receive(:perform_now).with(file_set_id, depositor.user_key).once + end + described_class.perform_now(work, depositor.user_key) + end +end diff --git a/spec/jobs/hyrax/grant_read_job_spec.rb b/spec/jobs/hyrax/grant_read_job_spec.rb new file mode 100644 index 0000000000..f3b0746633 --- /dev/null +++ b/spec/jobs/hyrax/grant_read_job_spec.rb @@ -0,0 +1,11 @@ +RSpec.describe Hyrax::GrantReadJob do + let(:depositor) { create(:user) } + let(:file_set) { build(:file_set) } + + it 'grants a user read access to a FileSet' do + expect(FileSet).to receive(:find).with(file_set.id).and_return(file_set) + expect(file_set).to receive(:read_users=).with(array_including(depositor.user_key)) + expect(file_set).to receive(:save!) + described_class.perform_now(file_set.id, depositor.user_key) + end +end diff --git a/spec/jobs/hyrax/grant_read_to_members_job_spec.rb b/spec/jobs/hyrax/grant_read_to_members_job_spec.rb new file mode 100644 index 0000000000..a6793fdb54 --- /dev/null +++ b/spec/jobs/hyrax/grant_read_to_members_job_spec.rb @@ -0,0 +1,16 @@ +RSpec.describe Hyrax::GrantReadToMembersJob do + let(:depositor) { create(:user) } + let(:work) { build(:work) } + let(:file_set_ids) { ['xyz123abc', 'abc789zyx'] } + + before do + allow_any_instance_of(described_class).to receive(:file_set_ids).with(work).and_return(file_set_ids) + end + + it 'loops over FileSet IDs, spawning a job for each' do + file_set_ids.each do |file_set_id| + expect(Hyrax::GrantReadJob).to receive(:perform_now).with(file_set_id, depositor.user_key).once + end + described_class.perform_now(work, depositor.user_key) + end +end diff --git a/spec/jobs/hyrax/revoke_edit_from_members_job_spec.rb b/spec/jobs/hyrax/revoke_edit_from_members_job_spec.rb new file mode 100644 index 0000000000..79e6c31da3 --- /dev/null +++ b/spec/jobs/hyrax/revoke_edit_from_members_job_spec.rb @@ -0,0 +1,16 @@ +RSpec.describe Hyrax::RevokeEditFromMembersJob do + let(:depositor) { create(:user) } + let(:work) { build(:work) } + let(:file_set_ids) { ['xyz123abc', 'abc789zyx'] } + + before do + allow_any_instance_of(described_class).to receive(:file_set_ids).with(work).and_return(file_set_ids) + end + + it 'loops over FileSet IDs, spawning a job for each' do + file_set_ids.each do |file_set_id| + expect(Hyrax::RevokeEditJob).to receive(:perform_now).with(file_set_id, depositor.user_key).once + end + described_class.perform_now(work, depositor.user_key) + end +end diff --git a/spec/jobs/hyrax/revoke_edit_job_spec.rb b/spec/jobs/hyrax/revoke_edit_job_spec.rb new file mode 100644 index 0000000000..5c3ca93484 --- /dev/null +++ b/spec/jobs/hyrax/revoke_edit_job_spec.rb @@ -0,0 +1,11 @@ +RSpec.describe Hyrax::RevokeEditJob do + let(:depositor) { create(:user) } + let(:file_set) { build(:file_set, user: depositor) } + + it 'revokes edit access from a FileSet' do + expect(FileSet).to receive(:find).with(file_set.id).and_return(file_set) + expect(file_set).to receive(:edit_users=).with([]) + expect(file_set).to receive(:save!) + described_class.perform_now(file_set.id, depositor.user_key) + end +end