Reputation: 187
I have a failure while testing this code... The error stated is "expecting <"admin/dashboard"> but rendering with <[]>"
The integration test page code snippet is
require 'test_helper'
class SiteLayoutTest < ActionDispatch::IntegrationTest
def setup
@admin = admins(:admn)
end
test "admin dashboard link" do
get login_admin_path
post login_admin_path, params: { session: { username: @admin.username,
password: 'Ha66y@Air' } }
get admin_dashboard_path
assert_template 'admin/dashboard'
end
end
The code snippet in route.rb is
get '/admin/dashboard', to: 'admin#dashboard'
The code snippet in the login controller is
def create
admin = Admin.find_by(username: params[:session][:username])
if admin && admin.authenticate(params[:session][:password])
# render 'admin/dashboard'
log_in admin
params[:session][:remember_me] == '1' ? remember(admin) : forget(admin)
redirect_to admin_dashboard_path
else
render 'login/admin'
flash.now[:danger] = 'Invalid email/password combination'
end
end
Code snippet in the admin controller is
def dashboard
redirect_to root_url unless logged_in?
@admin = current_user
end
The code snippet for the admins.yml is
admn:
username: "adminm"
password_digest: <%= Admin.digest('admin') %>
The app ran successfully in the server. However the error occurs while running the tests.
Upvotes: 1
Views: 101
Reputation: 5343
The line redirect_to admin_dashboard_path
does not render a template, it renders a redirection command; an HTTP 302. The browser then immediately fetches the specified page, which is why the manual test passed. Try assert_redirected_to
.
Upvotes: 1