Open
Description
What Ruby, Rails and RSpec versions are you using?
Ruby version: 2.5.1
Rails version: 5.2
Rspec version: 3.9.0
Observed behaviour
When adding an anonymous controller to a controller test suite, it breaks the delete route. Removing the anonymous controller leaves everything else working fine.
Expected behaviour
I expect:
delete :destroy
To not throw:
ActionController::UrlGenerationError:
No route matches {:action=>"destroy", :controller=>"sessions"}
When an anonymous controller is present.
# Test layout rendering
controller do
def test_index
render 'anonymous/index'
end
end
Can you provide an example app?
- Running this test, the anonymous controller test passes.
- The delete session tests fail with the error
ActionController::UrlGenerationError: No route matches {:action=>"destroy", :controller=>"sessions"}
require 'rails_helper'
RSpec.describe SessionsController, type: :controller do
# Resources
let(:manager) { create(:manager) }
# Test layout rendering
controller do
def test_index
render 'anonymous/index'
end
end
describe 'defaults to unauthenticated layout' do
before do
routes.draw { get 'test_index' => 'sessions#test_index' }
get :test_index
end
it 'renders the unauthenticated layout' do
expect(subject).to render_template('layouts/unauthenticated/base')
end
end
describe "DELETE #destroy" do
before do
login(manager)
delete :destroy
end
it 'redirects to the login path' do
expect(response).to redirect_to(login_path)
end
it "returns http 302" do
expect(response).to have_http_status(302)
end
end
end
If the anonymous controller is removed, the delete paths run as expected.
require 'rails_helper'
RSpec.describe SessionsController, type: :controller do
# Resources
let(:manager) { create(:manager) }
describe "DELETE #destroy" do
before do
login(manager)
delete :destroy
end
it 'redirects to the login path' do
expect(response).to redirect_to(login_path)
end
it "returns http 302" do
expect(response).to have_http_status(302)
end
end
end