Hi,
I have been looking through google for about an hour now and still don’t have a solution.
I am testing to make sure admin users get redirected to the admin dashboard if they are signed in, and back to the login page if they are not, I am trying to use the sign_in
method provided by the Devise::TestHelpers
.
Can anyone help? This is what I have.
Spec Helper
...
config.include Devise::TestHelpers, type: :controller
...
Controller Spec
require 'spec_helper'
describe AdminDashboardsController do
it 'redirects to admin login if the user is not logged in' do
get :show
expect(response).to redirect_to new_admin_session_path
end
it 'redirects to admin dashboard if the user is logged in' do
admin = create(:admin)
@request.env['devise.mapping'] = Devise.mappings[:admin]
sign_in admin
get :show
expect(response).to redirect_to admin_dashboard_path
end
end
Routes
Shopping::Application.routes.draw do
devise_for :admins, controllers: {
sessions: 'admins/sessions',
passwords: 'admins/passwords',
unlocks: 'admins/unlocks'
}
resource :admin_dashboard, only: [:show]
end
admin_dashboard GET /admin_dashboard(.:format) admin_dashboards#show
Controller
class AdminDashboardsController < ApplicationController
before_filter :authenticate_admin!, only: [:show]
def show
end
end
**Error **
1) AdminDashboardsController redirects to admin dashboard if the user is logged in
Failure/Error: expect(response).to redirect_to admin_dashboard_path
Expected response to be a <redirect>, but was <200>
# ./spec/controllers/admin_dashboards_controller_spec.rb:18:in `block (2 levels) in <top (required)>'
Any help is appreciated, I think I have included everything.