Skip to content

Spec helper rails helper improvements#49

Open
ShanaLMoore wants to merge 9 commits intomainfrom
spec-helper-rails-helper-improvements
Open

Spec helper rails helper improvements#49
ShanaLMoore wants to merge 9 commits intomainfrom
spec-helper-rails-helper-improvements

Conversation

@ShanaLMoore
Copy link
Copy Markdown
Contributor

@ShanaLMoore ShanaLMoore commented Mar 6, 2026

Contributes back upstream from upgrading to Hyku7 downstream (hyku up knapsack)

Summary

  • Fix spec_helper.rb to load hyrax-webapp/spec/spec_helper.rb instead of its rails_helper.rb, which caused double-boot and circular require issues.
  • Rewrite spec/rails_helper.rb for Hyku 7 / Rails 7.2 compatibility: set required ENV vars before booting Rails, boot Rails before requiring spec_helper, configure Valkyrie models, expand FactoryBot paths to include Hyrax shared spec factories and hyrax-webapp factories, add DatabaseCleaner with transaction strategy, and add standard RSpec helper includes (Devise, Warden, FactoryBot, ActiveJob, etc.).
  • Add RoleMapper.add shim: Hyku 7 removed this method; the shim delegates to Rolify so shared specs that call it continue to work.
  • Fix schema_loader_config_search_paths prepend in both config/initializers/hyrax.rb and lib/hyku_knapsack/engine.rb: Rails 7 config arrays may be frozen, so use reassignment (= [root] + Array(paths)) instead of unshift.

Ticket Number

Expected Behavior

  • Specs in a knapsack boot without circular require errors or double-initialization.
  • Shared Hyrax examples (e.g. it_behaves_like "a Hyrax::Work") resolve factories correctly.
  • schema_loader_config_search_paths prepend does not raise FrozenError under Rails 7.

orangewolf and others added 7 commits November 15, 2025 15:10
- Boot Rails from knapsack rails_helper (after ENV) then require only webapp spec_helper
- Set ENV to mirror hyrax-webapp test env; keep HYRAX_FLEXIBLE default false
- Use config.fixture_paths (plural); add Hyrax + webapp factory paths
- Set Hyrax Valkyrie test config; add DatabaseCleaner, Devise, Warden, ActiveJob includes

Made-with: Cursor
The shim was accidentally placed inside the RSpec.configure block
between config.before and config.after. Move it after the configure
block where it belongs as a top-level method definition.
…elper

spec_helper now loads hyrax-webapp/spec/spec_helper.rb which requires
Rails to already be initialized. Any spec file that touches Rails must
require rails_helper (which boots Rails first) rather than spec_helper.
Copy link
Copy Markdown

@laritakr laritakr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about the work resource generator? Should we also update the generators so new works are generated correctly?

@ShanaLMoore
Copy link
Copy Markdown
Contributor Author

ShanaLMoore commented Mar 6, 2026

@laritakr Are you talking about with the flexible flag? I'd consider that to be separate work. I'm only plucking from the generic things done in this PR

@ShanaLMoore ShanaLMoore requested a review from orangewolf March 6, 2026 22:27
ShanaLMoore and others added 2 commits March 13, 2026 07:49
- rails_helper: also load Rails.root/spec/support/**/*.rb so knapsacks
  can add their own support files (WebMock, etc.) without patching the helper
- .gitignore: add pry_history, CLAUDE.md, settings.local.json

Ported from notch8/palni_palci_knapsack#561.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Respect Hyku’s default: HYRAX_FLEXIBLE is off unless set by the app (e.g. .env, docker-compose).
Set before engine is required so that it takes effect before other models are loaded.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants