Skip to content

Commit

Permalink
Add spec coverage to grant/revoke jobs
Browse files Browse the repository at this point in the history
Refs #1477
  • Loading branch information
mjgiarlo committed Aug 14, 2017
1 parent fab61e0 commit 8c4e9e3
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .rubocop_fixme.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
11 changes: 11 additions & 0 deletions spec/jobs/hyrax/grant_edit_job_spec.rb
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions spec/jobs/hyrax/grant_edit_to_members_job_spec.rb
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions spec/jobs/hyrax/grant_read_job_spec.rb
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions spec/jobs/hyrax/grant_read_to_members_job_spec.rb
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions spec/jobs/hyrax/revoke_edit_from_members_job_spec.rb
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions spec/jobs/hyrax/revoke_edit_job_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8c4e9e3

Please sign in to comment.