This commit is contained in:
2025-11-07 13:34:32 -08:00
commit 1e8c5a972b
436 changed files with 11000 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
require "test_helper"
class Books::BookmarksControllerTest < ActionDispatch::IntegrationTest
setup do
sign_in :kevin
end
test "show includes a link to read the last read leaf" do
cookies["reading_progress_#{books(:handbook).id}"] = "#{leaves(:welcome_page).id}/3"
get book_bookmark_url(books(:handbook))
assert_response :success
assert_select "a", /Resume reading/
end
test "show includes a link to start reading if the last read leaf has been trashed" do
leaves(:welcome_page).trashed!
cookies["reading_progress_#{books(:handbook).id}"] = "#{leaves(:welcome_page).id}/3"
get book_bookmark_url(books(:handbook))
assert_response :success
assert_select "a", /Start reading/
end
test "show includes a link to start reading if no reading progress has been recorded" do
get book_bookmark_url(books(:handbook))
assert_response :success
assert_select "a", /Start reading/
end
end

View File

@@ -0,0 +1,25 @@
require "test_helper"
class Books::Leaves::MovesControllerTest < ActionDispatch::IntegrationTest
setup do
sign_in :kevin
end
test "moving a single item" do
assert_equal [ leaves(:welcome_section), leaves(:welcome_page), leaves(:summary_page), leaves(:reading_picture) ], books(:handbook).leaves.positioned
post book_leaves_moves_url(books(:handbook), id: leaves(:welcome_page).id, position: 0)
assert_response :no_content
assert_equal [ leaves(:welcome_page), leaves(:welcome_section), leaves(:summary_page), leaves(:reading_picture) ], books(:handbook).leaves.positioned
end
test "moving multiple items" do
assert_equal [ leaves(:welcome_section), leaves(:welcome_page), leaves(:summary_page), leaves(:reading_picture) ], books(:handbook).leaves.positioned
post book_leaves_moves_url(books(:handbook), id: leaves(:summary_page, :reading_picture).map(&:id), position: 1)
assert_response :no_content
assert_equal [ leaves(:welcome_section), leaves(:summary_page), leaves(:reading_picture), leaves(:welcome_page) ], books(:handbook).leaves.positioned
end
end

View File

@@ -0,0 +1,32 @@
require "test_helper"
class Books::PublicationsTest < ActionDispatch::IntegrationTest
setup do
@book = books(:manual)
sign_in :david
end
test "publish a book" do
assert_changes -> { @book.reload.published? }, from: false, to: true do
patch book_publication_url(@book), params: { book: { published: "1" } }
end
@book.reload
assert_redirected_to book_slug_url(@book)
assert_equal "manual", @book.slug
end
test "edit book slug" do
@book.update! published: true
get edit_book_publication_url(@book)
assert_response :success
patch book_publication_url(@book), params: { book: { slug: "new-slug" } }
@book.reload
assert_redirected_to book_slug_url(@book)
assert_equal "new-slug", @book.slug
end
end