I'm writing a feature test for a Rails 7 application. I'm using RSpec, Capybara, and Capybara-Webkit.
The feature I'm testing archives a record(a developer app) when the user clicks an 'Archive' button. The action uses a PUT method. It all works in the browser, but when I run my test, the test is trying to use a GET to hit this path and errors out when it can't find the route.
If I change the route to use GET, the test runs fine, but this wouldn't be the correct method to use for updating a record to be archived.
Why would the click event in the test use a GET instead of a PUT?
Failure/Error: raise ActionController::RoutingError, "No route matches [#{env['REQUEST_METHOD']}] #{env['PATH_INFO'].inspect}"
ActionController::RoutingError:
No route matches [GET] "/developer_apps/1/archive"
My spec:
scenario "can archive their developer app", js: true do
visit developer_app_path(@developer_app)
click_on 'Archive'
expect(page).to have_content "Developer app archived"
expect(page).to have_content "Status: Archived"
end
The button in the view:
<%= link_to "Archive", archive_developer_app_path(@developer_app), class: 'btn btn-danger', data: { "turbo-method": :put, turbo_confirm: "Are you sure?" } %>
The route:
put '/developer_apps/:id/archive', to: 'developer_apps#archive', as: :archive_developer_app