Skip to content

Commit

Permalink
Refactor publication_workflow_spec for reusable setup
Browse files Browse the repository at this point in the history
We're going to need to reuse the workflow setup here elsewhere, so I'm making it
as repeatable as possible. This removes the `before` block from the setup
entirely, opting for spec metadata and a custom factory build strategy to handle
the behaviors captured there before.
  • Loading branch information
Tom Johnson committed Nov 22, 2017
1 parent 47ae91d commit b33b5a1
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 15 deletions.
4 changes: 4 additions & 0 deletions spec/factories/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
id { ActiveFedora::Noid::Service.new.mint }
title ["Image: #{FFaker::Movie.title}"]
visibility Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC

transient do
user nil
end
end
end
21 changes: 6 additions & 15 deletions spec/features/publication_workflow_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,13 @@
require 'active_fedora/cleaner'
include Warden::Test::Helpers

RSpec.feature 'deposit and publication' do
let(:depositing_user) { FactoryGirl.create(:user) }
let(:publishing_user) { FactoryGirl.create(:admin) }
let(:work) { FactoryGirl.create(:image) }
RSpec.feature 'deposit and publication', :clean, :workflow do
let(:depositing_user) { FactoryGirl.create(:user) }
let!(:publishing_user) { FactoryGirl.create(:admin) }

let(:work) { FactoryGirl.actor_create(:image, user: depositing_user) }

context 'a logged in user' do
before do
ActiveFedora::Cleaner.clean!
DatabaseCleaner.clean_with(:truncation)
Tufts::WorkflowSetup.setup
allow(CharacterizeJob).to receive(:perform_later) # There is no fits installed on travis-ci
publishing_user # Make sure publishing user exists before the work is submitted
current_ability = ::Ability.new(depositing_user)
attributes = {}
env = Hyrax::Actors::Environment.new(work, current_ability, attributes)
Hyrax::CurationConcern.actor.create(env)
end
scenario "non-admin user deposits, admin publishes", js: true do
# All works go to the default admin set, which uses the mira_publication_workflow
expect(work.active_workflow.name).to eq "mira_publication_workflow"
Expand Down
2 changes: 2 additions & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
#
Dir[Rails.root.join('spec', 'support', '**', '*.rb')].each { |f| require f }

FactoryGirl.register_strategy(:actor_create, ActorCreate)

# Checks for pending migration and applies them before tests are run.
# If you are not using ActiveRecord, you can remove this line.
ActiveRecord::Migration.maintain_test_schema!
Expand Down
25 changes: 25 additions & 0 deletions spec/support/build_strategies/actor_create.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class ActorCreate
def initialize
@association_strategy = FactoryGirl.strategy_by_name(:create).new
end

delegate :association, to: :@association_strategy

def result(evaluation)
evaluation.object.tap do |instance|
evaluation.notify(:after_build, instance)

evaluator = evaluation.instance_variable_get(:@attribute_assigner)
.instance_variable_get(:@evaluator)

ability = Ability.new(evaluator.user)
env = Hyrax::Actors::Environment.new(instance, ability, {})

evaluation.notify(:before_create, instance)
evaluation.notify(:before_actor_create, instance)
Hyrax::CurationConcern.actor.create(env)
evaluation.notify(:after_create, instance)
evaluation.notify(:after_actor_create, instance)
end
end
end

0 comments on commit b33b5a1

Please sign in to comment.