Skip to content

Commit

Permalink
Ensure Failure doesn't fail to return
Browse files Browse the repository at this point in the history
  • Loading branch information
cjcolvar authored and tamsin johnson committed Feb 3, 2022
1 parent c831ecd commit 6dd535e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions .rubocop_fixme.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ RSpec/AnyInstance:
- 'spec/controllers/hyrax/stats_controller_spec.rb'
- 'spec/controllers/hyrax/users_controller_spec.rb'
- 'spec/hyrax/transactions/steps/delete_access_control_spec.rb'
- 'spec/hyrax/transactions/steps/save_access_control_spec.rb'
- 'spec/jobs/content_restored_version_event_job_spec.rb'
- 'spec/jobs/file_set_attached_event_job_spec.rb'
- 'spec/jobs/hyrax/grant_edit_to_members_job_spec.rb'
Expand Down
4 changes: 2 additions & 2 deletions lib/hyrax/transactions/steps/save_access_control.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class SaveAccessControl
# @return [Dry::Monads::Result]
def call(obj)
return Success(obj) unless obj.respond_to?(:permission_manager)
obj.permission_manager&.acl&.save ||
(return Failure[:failed_to_save_acl, acl])
acl = obj.permission_manager&.acl
acl&.save || (return Failure[:failed_to_save_acl, acl])

Success(obj)
end
Expand Down
11 changes: 11 additions & 0 deletions spec/hyrax/transactions/steps/save_access_control_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@
.to change { Hyrax::AccessControlList.new(resource: work).permissions }
.to contain_exactly(have_attributes(mode: :read, agent: user.user_key))
end

context 'when it fails to update' do
before { allow_any_instance_of(Hyrax::AccessControlList).to receive(:save).and_return(false) }

it 'returns a Failure' do
result = step.call(work)

expect(result).to be_failure
expect(result.failure).to contain_exactly(Symbol, Hyrax::AccessControlList)
end
end
end

context 'when the resource has no permission_manager' do
Expand Down

0 comments on commit 6dd535e

Please sign in to comment.