Skip to content

Commit

Permalink
🧹 Update knapsack files
Browse files Browse the repository at this point in the history
We were getting this error:

```
KeyError:
  Factory not registered: “hyrax_admin_set”
```

Ultimately we synced up everything with Pals Knapsack which made this
work.
  • Loading branch information
Kirk Wang committed Jun 10, 2024
1 parent f396708 commit d597e18
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 11 deletions.
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--require rails_helper
2 changes: 1 addition & 1 deletion app/services/hyrax/simple_schema_loader_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
module Hyrax
module SimpleSchemaLoaderDecorator
def config_search_paths
super + [HykuKnapsack::Engine.root]
[HykuKnapsack::Engine.root] + super
end
end
end
Expand Down
9 changes: 7 additions & 2 deletions lib/hyku_knapsack/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -43,17 +43,22 @@ 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

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
]
Expand Down
20 changes: 13 additions & 7 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
3 changes: 2 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions spec/support/fixtures.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d597e18

Please sign in to comment.