Skip to content

Commit

Permalink
🧹 Clean up actors
Browse files Browse the repository at this point in the history
Just found one actor that was overriding Hyrax.  This commit will switch
it to a decorator.
  • Loading branch information
kirkkwang committed Dec 20, 2023
1 parent 4319562 commit d35b250
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
# frozen_string_literal: true

# OVERRIDE Hyrax 2.9 to add in import flag
# OVERRIDE Hyrax v5.0.0rc2 to add in import flag

module Hyrax
module Actors
class Environment
module EnvironmentDecoractor
# @param [ActiveFedora::Base] curation_concern work to operate on
# @param [Ability] current_ability the authorizations of the acting user
# @param [ActionController::Parameters] attributes user provided form attributes
def initialize(curation_concern, current_ability, attributes, importing = false)
@curation_concern = curation_concern
@current_ability = current_ability
@attributes = attributes.to_h.with_indifferent_access
@importing = importing
super(curation_concern, current_ability, attributes)
end

attr_reader :curation_concern, :current_ability, :attributes, :importing

# @return [User] the user from the current_ability
def user
current_ability.current_user
end
attr_reader :importing
end
end
end

Hyrax::Actors::Environment.prepend(Hyrax::Actors::EnvironmentDecoractor)
26 changes: 26 additions & 0 deletions spec/actors/hyrax/environment_decorator_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

RSpec.describe Hyrax::Actors::Environment, type: :decorator do
let(:curation_concern) { double('curation_concern') }
let(:current_ability) { double('current_ability') }
let(:attributes) { {} }

describe '#initialize' do
context 'when importing is not explicitly set' do
subject { described_class.new(curation_concern, current_ability, attributes) }

it 'initializes with an importing flag set to false (default behavior)' do
expect(subject.importing).to eq(false)
end
end

context 'when importing is explicitly set' do
let(:importing) { true }
subject { described_class.new(curation_concern, current_ability, attributes, importing) }

it 'initializes with an importing flag set to true' do
expect(subject.importing).to eq(true)
end
end
end
end

0 comments on commit d35b250

Please sign in to comment.