Skip to content

Commit

Permalink
Merge pull request #5589 from solidusio/elia/mock-component-fix
Browse files Browse the repository at this point in the history
[admin] Fix mock components reported location
  • Loading branch information
elia authored Jan 9, 2024
2 parents 6ef5c78 + 82dcf1e commit 9692a68
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
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 9692a68

Please sign in to comment.