This commit is contained in:
33
test/controllers/books/bookmarks_controller_test.rb
Normal file
33
test/controllers/books/bookmarks_controller_test.rb
Normal 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
|
||||
25
test/controllers/books/leaves/moves_controller_test.rb
Normal file
25
test/controllers/books/leaves/moves_controller_test.rb
Normal 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
|
||||
32
test/controllers/books/publications_controller_test.rb
Normal file
32
test/controllers/books/publications_controller_test.rb
Normal 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
|
||||
Reference in New Issue
Block a user