From 73bc29eedacbf914107e71976ced12e5b8147b70 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Tue, 9 Jan 2024 12:33:25 +0100 Subject: [PATCH 1/2] Ensure ViewComponent warnings for mock components report the correct location --- .../support/solidus_admin/component_helpers.rb | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/admin/spec/support/solidus_admin/component_helpers.rb b/admin/spec/support/solidus_admin/component_helpers.rb index e68d7d37c9d..49833a4687d 100644 --- a/admin/spec/support/solidus_admin/component_helpers.rb +++ b/admin/spec/support/solidus_admin/component_helpers.rb @@ -12,13 +12,14 @@ module ComponentHelpers # end # end def mock_component(&definition) - Class.new(SolidusAdmin::BaseComponent) do - # ViewComponent will complain if we don't fake a class name: - # @see https://github.com/ViewComponent/view_component/blob/5decd07842c48cbad82527daefa3fe9c65a4226a/lib/view_component/base.rb#L371 - def self.name - "Foo" - end - end.tap { |klass| klass.class_eval(&definition) if definition } + location = caller(1, 1).first + component_class = Class.new(SolidusAdmin::BaseComponent) + # ViewComponent will complain if we don't fake a class name: + # @see https://github.com/ViewComponent/view_component/blob/5decd07842c48cbad82527daefa3fe9c65a4226a/lib/view_component/base.rb#L371 + component_class.define_singleton_method(:name) { "Foo" } + component_class.define_singleton_method(:to_s) { "#{name} (#{location})" } + component_class.class_eval(&definition) if definition + component_class end end end From 82dcf1ed4e0445409cc16769a35cac0c5224f7a2 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Tue, 9 Jan 2024 12:33:51 +0100 Subject: [PATCH 2/2] Make navigation mock components return a safe string --- .../solidus_admin/layout/navigation/component_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin/spec/components/solidus_admin/layout/navigation/component_spec.rb b/admin/spec/components/solidus_admin/layout/navigation/component_spec.rb index b537c744526..f5480e5977a 100644 --- a/admin/spec/components/solidus_admin/layout/navigation/component_spec.rb +++ b/admin/spec/components/solidus_admin/layout/navigation/component_spec.rb @@ -34,7 +34,7 @@ it "renders the account nav component" do account_component = mock_component do def call - "account nav" + "account nav".html_safe end end component = described_class.new(