I was testing my Rails 5.0 application with the following code:
test "destroy should require logged-in user" do
assert_no_difference 'AtpSelection.count' do
delete :destroy, params: { id: atp_selections(:selection_1) }
end
assert_redirected_to login_url
end
but the test kept failing:
ERROR["test_destroy_should_require_logged-in_user", AtpSelectionsControllerTest, 1.9559332270000596]
test_destroy_should_require_logged-in_user#AtpSelectionsControllerTest (1.96s)
URI::InvalidURIError: URI::InvalidURIError: bad URI(is not URI?): http://www.example.com:80destroy
So, in order for the test to pass, I had to change my code using instead the following code:
test "destroy should require logged-in user" do
assert_no_difference 'AtpSelection.count' do
delete atp_selection_path(atp_selections(:selection_1))
end
assert_redirected_to login_url
end
I have no idea why I could not make the test pass calling delete
directly on the controller action :destroy
. I made this same choice in other tests I created before for other controllers and they succeed without raising errors.
Aucun commentaire:
Enregistrer un commentaire