From 285f84ec7708daace04d6a628c6a818b11972c6b Mon Sep 17 00:00:00 2001 From: Shana Moore Date: Thu, 23 Oct 2025 11:26:25 -0700 Subject: [PATCH 1/2] [i41] - Fix view specs to prioritize knapsack views over hyrax-webapp views Issue - https://github.com/samvera-labs/hyku_knapsack/issues/41 Add knapsack_view_helpers.rb to automatically prepend knapsack view paths for all view specs - Fix Fixtures::FixtureFileUpload error in rails_helper.rb by making it conditional - This allows view specs in the knapsack to correctly test knapsack view overlays" --- spec/rails_helper.rb | 3 ++- spec/support/knapsack_view_helpers.rb | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 spec/support/knapsack_view_helpers.rb diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 9a6340f..c93e04d 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -42,5 +42,6 @@ # TODO is this needed? config.include HykuKnapsack::Engine.routes.url_helpers config.include Capybara::DSL - config.include Fixtures::FixtureFileUpload + # Only include Fixtures::FixtureFileUpload if it's defined (from hyrax-webapp) + config.include Fixtures::FixtureFileUpload if defined?(Fixtures::FixtureFileUpload) end diff --git a/spec/support/knapsack_view_helpers.rb b/spec/support/knapsack_view_helpers.rb new file mode 100644 index 0000000..7222490 --- /dev/null +++ b/spec/support/knapsack_view_helpers.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +# This shared context ensures that view specs in the knapsack correctly +# prioritize knapsack views over hyrax-webapp views. +# +# Usage: +# RSpec.describe 'path/to/view.html.erb', type: :view do +# include_context 'with knapsack view paths' +# # ... your spec code +# end +# +RSpec.shared_context 'with knapsack view paths' do + before do + # Prepend the knapsack view paths so that views in the knapsack + # take precedence over views in hyrax-webapp. + # This mimics what happens in production via the Engine's after_initialize hook. + view.view_paths.unshift(HykuKnapsack::Engine.root.join('app', 'views')) + end +end + +# Automatically include this context for all view specs in the knapsack +RSpec.configure do |config| + config.include_context 'with knapsack view paths', type: :view +end + From f6eda883ad94cbcfb89a8e552c731ce0bc61e638 Mon Sep 17 00:00:00 2001 From: Shana Moore Date: Thu, 23 Oct 2025 14:09:29 -0700 Subject: [PATCH 2/2] :lipstick: Fix rubocop issue and runner --- .rubocop.yml | 2 ++ hyku_knapsack.gemspec | 2 ++ spec/support/knapsack_view_helpers.rb | 1 - 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.rubocop.yml b/.rubocop.yml index 5217bfa..6bd4a90 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -5,10 +5,12 @@ AllCops: NewCops: disable TargetRubyVersion: 3.2.2 DisplayCopNames: true + SuggestExtensions: false Exclude: # NOTE: When we run knapsack's rubocop, we don't want to check the submodule # for Hyku. We'll assume it's okay and has it's own policing policies. - "hyrax-webapp/**/*" + - "gems/**/*" Metrics/BlockLength: AllowedMethods: ['included', 'describe', 'it', 'context'] diff --git a/hyku_knapsack.gemspec b/hyku_knapsack.gemspec index ffc994a..f025202 100644 --- a/hyku_knapsack.gemspec +++ b/hyku_knapsack.gemspec @@ -25,4 +25,6 @@ Gem::Specification.new do |spec| end spec.add_dependency "rails", ">= 5.2.0" + + spec.add_development_dependency "rubocop-rake" end diff --git a/spec/support/knapsack_view_helpers.rb b/spec/support/knapsack_view_helpers.rb index 7222490..210a28a 100644 --- a/spec/support/knapsack_view_helpers.rb +++ b/spec/support/knapsack_view_helpers.rb @@ -22,4 +22,3 @@ RSpec.configure do |config| config.include_context 'with knapsack view paths', type: :view end -