Skip to content

Commit

Permalink
Ensure ViewComponent warnings for mock components report the correct …
Browse files Browse the repository at this point in the history
…location
  • Loading branch information
elia committed Jan 9, 2024
1 parent 6ef5c78 commit 73bc29e
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions admin/spec/support/solidus_admin/component_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 73bc29e

Please sign in to comment.