forked from nicolas-brousse/view_component
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
set request full path manually for tests with request url (ViewCompon…
- Loading branch information
1 parent
6f30ab6
commit 087f33a
Showing
5 changed files
with
44 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class RequestUrlComponent < ViewComponent::Base | ||
def call | ||
content_tag(:span, request.path, class: "path") + content_tag(:span, request.fullpath, class: "fullpath") | ||
end | ||
end |
28 changes: 28 additions & 0 deletions
28
test/sandbox/test/components/request_url_component_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
require "test_helper" | ||
|
||
class RequestUrlComponentTest < ViewComponent::TestCase | ||
test "should print path and fullpath" do | ||
with_request_url "/products" do | ||
render_inline(RequestUrlComponent.new) | ||
|
||
assert_selector ".path", text: "/products" | ||
assert_selector ".fullpath", text: "/products" | ||
end | ||
|
||
with_request_url "/slots?param=1¶mtwo=2" do | ||
render_inline(RequestUrlComponent.new) | ||
|
||
assert_selector ".path", text: "/slots" | ||
assert_selector ".fullpath", text: "/slots?param=1¶mtwo=2" | ||
end | ||
|
||
with_request_url "/slots" do | ||
render_inline(RequestUrlComponent.new) | ||
|
||
assert_selector ".path", text: "/slots" | ||
assert_selector ".fullpath", text: "/slots" | ||
end | ||
end | ||
end |