diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..a35c44f --- /dev/null +++ b/.rspec @@ -0,0 +1 @@ +--require rails_helper diff --git a/app/services/hyrax/simple_schema_loader_decorator.rb b/app/services/hyrax/simple_schema_loader_decorator.rb index 7a9810c..b3d2f43 100644 --- a/app/services/hyrax/simple_schema_loader_decorator.rb +++ b/app/services/hyrax/simple_schema_loader_decorator.rb @@ -5,7 +5,7 @@ module Hyrax module SimpleSchemaLoaderDecorator def config_search_paths - super + [HykuKnapsack::Engine.root] + [HykuKnapsack::Engine.root] + super end end end diff --git a/lib/hyku_knapsack/engine.rb b/lib/hyku_knapsack/engine.rb index d73eb3f..d1fc165 100644 --- a/lib/hyku_knapsack/engine.rb +++ b/lib/hyku_knapsack/engine.rb @@ -21,7 +21,7 @@ def self.load_translations! # only add the migrations if they are not already copied # via the rake task. Allows gem to work both with the install:migrations # and without it. - if !app.root.to_s.match(root.to_s) && + if app.root.to_s != HykuKnapsack::Engine.root.to_s && app.root.join('db/migrate').children.none? { |path| path.fnmatch?("*.hyku_knapsack.rb") } config.paths["db/migrate"].expanded.each do |expanded_path| app.config.paths["db/migrate"] << expanded_path @@ -43,9 +43,12 @@ def self.load_translations! # omniauthable # ] # end + + # Ensure we are prepending the Hyrax::SimpleSchemaLoaderDecorator early + Hyrax::SimpleSchemaLoader.prepend(Hyrax::SimpleSchemaLoaderDecorator) end - config.after_initialize do + config.to_prepare do HykuKnapsack::Engine.root.glob("app/**/*_decorator*.rb").sort.each do |c| Rails.configuration.cache_classes ? require(c) : load(c) end @@ -53,7 +56,9 @@ def self.load_translations! HykuKnapsack::Engine.root.glob("lib/**/*_decorator*.rb").sort.each do |c| Rails.configuration.cache_classes ? require(c) : load(c) end + end + config.after_initialize do Hyrax::DerivativeService.services = [ IiifPrint::PluggableDerivativeService ] diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 9128b06..7dce724 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -1,22 +1,22 @@ # frozen_string_literal: true + # This file is copied to spec/ when you run 'rails generate rspec:install' require "spec_helper" require File.expand_path("hyku_specs/rails_helper.rb", __dir__) ENV["RAILS_ENV"] ||= "test" # require File.expand_path('../config/environment', __dir__) -require Rails.root.join("config", "environment") +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 "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 -if defined?(HykuAddons) - FactoryBot.definition_file_paths = [File.expand_path("spec/factories", HykuAddons::Engine.root)] - FactoryBot.find_definitions -end - +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 @@ -31,7 +31,7 @@ # require only the support files necessary. # # Require supporting ruby files from spec/support/ and subdirectories. Note: engine, not Rails.root context. -Dir[File.join(File.dirname(__FILE__), "support/**/*.rb")].each { |f| require f } +Dir[HykuKnapsack::Engine.root.join('spec', 'support', '**', '*.rb')].each { |f| require f } RSpec.configure do |config| # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures @@ -41,6 +41,12 @@ # config.include Rails.application.routes.url_helpers # TODO is this needed? config.include HykuKnapsack::Engine.routes.url_helpers + config.include Capybara::DSL + config.include Fixtures::FixtureFileUpload + # To run specs locally without the spec/hyku_specs/ directory do: `bundle exec rspec --tag ~hyku` + config.define_derived_metadata(file_path: %r{spec/hyku_specs/}) do |metadata| + metadata[:hyku] = true + end ## End override end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ec7b774..65f9472 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -3,7 +3,8 @@ RSpec.configure do |config| # Look for an overriding spec file and skip if it exists config.around do |example| - if example.file_path.starts_with?("./spec/hyku_specs") && File.exist?(example.file_path.sub("./spec/hyku_specs", ".")) + if example.file_path.starts_with?("./spec/hyku_specs") && + File.exist?(example.file_path.sub("./spec/hyku_specs", ".")) skip "Override exists of this test file in engine." else example.run diff --git a/spec/support/fixtures.rb b/spec/support/fixtures.rb new file mode 100644 index 0000000..2843b36 --- /dev/null +++ b/spec/support/fixtures.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module Fixtures + module FixtureFileUpload + def fixture_file(path) + File.open(fixture_file_path(path)) + end + + def fixture_file_path(path) + Rails.root + 'spec/fixtures' + path + end + end +end