我更改了after_sign_in_path_for
方法的默认行为,如下所示:
class ApplicationController < ActionController::Base
private
def after_sign_in_path_for(resource)
return admin_root_path if resource.is_a?(AdminUser)
request.referrer || root_path
end
end
它可以找到,现在我要通过minitest
对其进行测试。
但是我不知道该如何编写集成测试。
尽管rspec
有一个答案,但我不会为minitest
重写。
How to test after_sign_in_path_for(resource)?
如何为after_sign_in_path_for
的{{1}}编写测试?
路轨:5.1 设计:4.5.0
minitest
答案 0 :(得分:0)
您可以像这样测试它们:
require 'test_helper'
class ApplicationControllerTest < ActionDispatch::IntegrationTest
include Devise::Test::IntegrationHelpers
setup do
@user = create(:user)
@admin_user = create(:admin_user)
end
test "should redirect to current page after login" do
sign_in(@user)
get :index
assert_redirected_to controller: "home", action: "index"
end
test "should redirect to admin root page after login" do
sign_in(@adminuser)
get :index
assert_redirected_to controller: "admin", action: "index"
end
end