这就是我通过测试的原因:
首先,你应该纠正
books.yml
tmaas:
title: The Mysterious Affair at Styles
published: 1920
author: agatha_c
tgow:
title: The Grapes of Wrath
published: 1939
author: john_s
这是我的测试
book_controller
-
创建操作的测试:
test "should create book" do
assert_difference('Book.count') do
post author_books_url(@book.author), params: { book: {
author_id: @book.author_id,
title: @book.title,
published: @book.published
}}
end
assert_redirected_to author_book_url(Book.last.author, Book.last)
end
-
test "should update book" do
patch author_book_url(@book.author, @book), params: { book: {
author_id: @book.author_id,
title: @book.title,
published: @book.published
} }
assert_redirected_to author_book_url(@book.author, @book)
end
-
销毁操作测试:
test "should destroy book" do
assert_difference('Book.count', -1) do
delete author_book_url(@book.author, @book)
end
assert_redirected_to author_books_url(@book.author)
end
https://guides.rubyonrails.org/testing.html#functional-tests-for-your-controllers