Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions config/initializers/hyrax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
config.flexible = ActiveModel::Type::Boolean.new.cast(ENV.fetch('HYRAX_FLEXIBLE', 'false'))

# Prepend to ensure knapsack profile is checked before the host app's profiles.
config.schema_loader_config_search_paths.unshift(HykuKnapsack::Engine.root) \
if config.respond_to?(:schema_loader_config_search_paths)
if config.respond_to?(:schema_loader_config_search_paths)
paths = config.schema_loader_config_search_paths
config.schema_loader_config_search_paths = [HykuKnapsack::Engine.root] + Array(paths)
end
end
end
6 changes: 4 additions & 2 deletions lib/hyku_knapsack/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ def self.load_translations!
# end

# Prepend knapsack root so its config/metadata/*.yaml schemas are found first.
Hyrax.config.schema_loader_config_search_paths.unshift(HykuKnapsack::Engine.root) \
if Hyrax.config.respond_to?(:schema_loader_config_search_paths)
if Hyrax.config.respond_to?(:schema_loader_config_search_paths)
paths = Hyrax.config.schema_loader_config_search_paths
Hyrax.config.schema_loader_config_search_paths = [HykuKnapsack::Engine.root] + Array(paths)
end
end

config.to_prepare do
Expand Down
76 changes: 48 additions & 28 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,66 @@
ENV["RAILS_ENV"] ||= "test"
# Use Hyku default (false) unless a spec or .env sets HYRAX_FLEXIBLE.
ENV['HYRAX_FLEXIBLE'] ||= 'false'
# Mirror the env setup from hyrax-webapp/spec/rails_helper.rb so Rails initializers
# (especially analytics and routing) behave correctly in test mode.
ENV['HYKU_ADMIN_HOST'] = 'test.host'
ENV['HYKU_ROOT_HOST'] = 'test.host'
ENV['HYKU_ADMIN_ONLY_TENANT_CREATION'] = nil
ENV['HYKU_DEFAULT_HOST'] = nil
ENV['HYKU_MULTITENANT'] = 'true'
ENV['VALKYRIE_TRANSITION'] = 'true'
ENV['HYRAX_ANALYTICS_REPORTING'] = 'false'

require "spec_helper"

# require File.expand_path('../config/environment', __dir__)
# Boot Rails FIRST, before loading spec_helper.
# This ensures ENV is correctly set when Rails initializers run,
# and makes Rails.root available for spec_helper (which may load hyrax_with_valkyrie_helper).
require File.expand_path("../hyrax-webapp/config/environment", __dir__)
# Prevent database truncation if the environment is production
abort("The Rails environment is running in production mode!") if Rails.env.production?

require "spec_helper"
require "rspec/rails"
# Add additional requires below this line. Rails is not loaded until this point!
require "factory_bot_rails"
FactoryBot.definition_file_paths = [File.expand_path("spec/factories", HykuKnapsack::Engine.root)]
FactoryBot.find_definitions

require 'capybara/rails'
require 'dry-validation'
# Requires supporting ruby files with custom matchers and macros, etc, in
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
# run as spec files by default. This means that files in spec/support that end
# in _spec.rb will both be required and run as specs, causing the specs to be
# run twice. It is recommended that you do not name files matching this glob to
# end with _spec.rb. You can configure this pattern with the --pattern
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
#
# The following line is provided for convenience purposes. It has the downside
# of increasing the boot-up time by auto-requiring all files in the support
# directory. Alternatively, in the individual `*_spec.rb` files, manually
# require only the support files necessary.
#
# Require supporting ruby files from spec/support/ and subdirectories. Note: engine, not Rails.root context.
require 'database_cleaner'

# Configure Hyrax to use Valkyrie-based models in tests (matches hyrax-webapp rails_helper).
Hyrax.config.admin_set_model = "AdminSetResource"
Hyrax.config.collection_model = "CollectionResource"

# Load factories from Hyrax's shared specs, hyrax-webapp, and this engine.
# This allows specs to use Hyrax shared examples (e.g. "a Hyrax::Work") and webapp factories.
FactoryBot.definition_file_paths = [
Hyrax::Engine.root.join("lib/hyrax/specs/shared_specs/factories").to_s,
File.expand_path("spec/factories", Rails.root),
File.expand_path("spec/factories", HykuKnapsack::Engine.root)
]
FactoryBot.find_definitions

# Load only knapsack-specific support files (not all of hyrax-webapp's).
Dir[HykuKnapsack::Engine.root.join('spec', 'support', '**', '*.rb')].each { |f| require f }

ActiveRecord::Migration.maintain_test_schema!

RSpec.configure do |config|
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = Rails.root.join('spec', 'fixtures')
config.fixture_paths = [Rails.root.join('spec', 'fixtures')]
config.use_transactional_fixtures = false

# They enable url_helpers not to throw error in Rspec system spec and request spec.
# config.include Rails.application.routes.url_helpers
# TODO is this needed?
config.include HykuKnapsack::Engine.routes.url_helpers
config.include Capybara::DSL
# Only include Fixtures::FixtureFileUpload if it's defined (from hyrax-webapp)
config.include Fixtures::FixtureFileUpload if defined?(Fixtures::FixtureFileUpload)
config.include Devise::Test::ControllerHelpers, type: :controller
config.include FactoryBot::Syntax::Methods
config.include ApplicationHelper, type: :view
config.include Warden::Test::Helpers, type: :feature
config.include ActiveJob::TestHelper

config.before do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.start
end

Comment thread
ShanaLMoore marked this conversation as resolved.
Outdated
config.after do
DatabaseCleaner.clean
end
end
4 changes: 3 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# frozen_string_literal: true

require File.expand_path("../hyrax-webapp/spec/rails_helper.rb", __dir__)
# Load hyrax-webapp's spec_helper for WebMock, rspec-its, Valkyrie adapter registration,
# and shared RSpec configuration. Rails must already be booted before this is required
# (see rails_helper.rb which boots Rails first, then requires spec_helper).
require File.expand_path("../hyrax-webapp/spec/spec_helper.rb", __dir__)
Loading