Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

参考書籍一覧ページに必読マークを表示する #5674

Merged
merged 7 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions app/decorators/book_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

module BookDecorator
def must_read_for_any_practices?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decoratorに独自のメソッドを追加した場合は対応するテストが欲しい感じです〜

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

テストを追加しました!ご確認よろしくお願いいたします🙏

practices_books.any?(&:must_read)
end
end
2 changes: 2 additions & 0 deletions app/javascript/components/book.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
.card-books-item__rows
.card-books-item__row
h2.card-books-item__title
span.a-badge.is-danger.is-sm(v-if='book.mustRead')
| 必読
a.card-books-item__title-link(
:href='book.pageUrl',
target='_blank',
Expand Down
1 change: 1 addition & 0 deletions app/views/api/books/_book.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ json.description book.description
json.pageUrl book.page_url
json.coverUrl book.cover_url
json.editBookPath edit_book_path(book)
json.mustRead book.must_read_for_any_practices?

json.practices book.practices, partial: "api/books/practice", as: :practice
15 changes: 15 additions & 0 deletions test/decorators/book_decorator_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

require 'test_helper'

class BookDecoratorTest < ActiveSupport::TestCase
setup do
@book1 = ActiveDecorator::Decorator.instance.decorate(books(:book1))
@book2 = ActiveDecorator::Decorator.instance.decorate(books(:book2))
end

test '#must_read_for_any_practices?' do
assert @book1.must_read_for_any_practices?
assert_not @book2.must_read_for_any_practices?
end
end