Skip to content

Commit

Permalink
Refactor WorkflowSetup to speed up tests
Browse files Browse the repository at this point in the history
WorkflowSetup is a very slow process, so we benefit from calling
as few times as possible.  This set of changes refactors applicable
tests to call WorkflowSetup once at the beginning of all tests in
a test group rather than once per individual test.
  • Loading branch information
mark-dce committed Mar 20, 2023
1 parent 083b438 commit 1dae610
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
15 changes: 7 additions & 8 deletions spec/controllers/hyrax/etds_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
# `rails generate hyrax:work Etd`
require 'rails_helper'

RSpec.describe Hyrax::EtdsController, :perform_jobs, :clean do
let(:user) { create :user }
RSpec.describe Hyrax::EtdsController, :perform_jobs do
before :all do
ActiveFedora::Cleaner.clean!
# ensure clean! is called before rather than after WorkflowSetup - i.e. avoid using use :clean tag
WorkflowSetup.new("#{fixture_path}/config/emory/superusers.yml", "#{fixture_path}/config/emory/ec_admin_sets.yml", "/dev/null").setup
end

let(:user) { create :user }
let(:approver) { User.where(uid: "tezprox").first }
let(:workflow_setup) { WorkflowSetup.new("#{fixture_path}/config/emory/superusers.yml", "#{fixture_path}/config/emory/ec_admin_sets.yml", "/dev/null") }

let(:file1) { File.open("#{fixture_path}/miranda/miranda_thesis.pdf") }
let(:file2) { File.open("#{fixture_path}/magic_warrior_cat.jpg") }
Expand Down Expand Up @@ -41,7 +45,6 @@
end

before do
workflow_setup.setup
etd.assign_admin_set

# Create the ETD record
Expand Down Expand Up @@ -132,10 +135,6 @@
end

describe "POST create" do
before do
workflow_setup.setup
end

it "creates an etd" do
expect {
post :create, params: { etd: { title: 'a title', school: 'Emory College', department: 'Art History' } }
Expand Down
10 changes: 6 additions & 4 deletions spec/system/check_school_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# frozen_string_literal: true
require 'rails_helper'

RSpec.feature 'Selected school', :clean, integration: true, js: true, type: :system do
RSpec.feature 'Selected school', integration: true, js: true, type: :system do
before :all do
ActiveFedora::Cleaner.clean!
WorkflowSetup.new("#{fixture_path}/config/emory/superusers.yml", "#{fixture_path}/config/emory/ec_admin_sets.yml", "/dev/null").setup
end

let(:user) { create :user }

let(:approver) { User.where(uid: "tezprox").first }
Expand All @@ -21,10 +26,7 @@
FactoryBot.build(:etd, default_attrs)
end

let(:workflow_setup) { WorkflowSetup.new("#{fixture_path}/config/emory/superusers.yml", "#{fixture_path}/config/emory/ec_admin_sets.yml", "/dev/null") }

before do
workflow_setup.setup
ec_etd.assign_admin_set

# Create the ETD record
Expand Down

0 comments on commit 1dae610

Please sign in to comment.