Skip to content

Commit

Permalink
Merge pull request #5674 from fjordllc/feature/display-must-read-mark…
Browse files Browse the repository at this point in the history
…-in-books

参考書籍一覧ページに必読マークを表示する
  • Loading branch information
komagata authored Nov 14, 2022
2 parents 36ee3a0 + 9588b9f commit fbcc104
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
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?
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

0 comments on commit fbcc104

Please sign in to comment.