-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7674 from fjordllc/chore/introduce-view-component
view componentを導入
- Loading branch information
Showing
9 changed files
with
58 additions
and
7 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
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,23 @@ | ||
# frozen_string_literal: true | ||
|
||
class Works::WorkComponent < ViewComponent::Base | ||
def initialize(work:) | ||
@work = work | ||
end | ||
|
||
def thumbnail | ||
if work.thumbnail.attached? | ||
image_tag work.thumbnail_url, class: 'thumbnail-card__image' | ||
else | ||
image_tag('work-blank.svg', class: 'thumbnail-card__image') | ||
end | ||
end | ||
|
||
def creator_avatar | ||
image_tag work.user.avatar_url, title: work.user.icon_title, class: 'a-user-icons__item-icon a-user-icon' | ||
end | ||
|
||
private | ||
|
||
attr_reader :work | ||
end |
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,20 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test_helper' | ||
|
||
class WorkComponentTest < ViewComponent::TestCase | ||
setup do | ||
@user = users(:kimura).extend(UserDecorator) | ||
@work = works(:work1) | ||
@work.user = @user | ||
render_inline(Works::WorkComponent.new(work: @work)) | ||
end | ||
|
||
def test_thumbnail | ||
assert_selector 'img.thumbnail-card__image' | ||
end | ||
|
||
def test_creator_avatar | ||
assert_selector 'img.a-user-icons__item-icon.a-user-icon[title="kimura (Kimura Tadasi)"][src="/images/users/avatars/default.png"]' | ||
end | ||
end |