我已经为 Active Admin 中的一些资源定义了我自己的控制器和 member_actions,现在我不知道如何使用 ActiveSupport::TestCase 测试它们。
任何帮助将不胜感激,谢谢。
我已经为 Active Admin 中的一些资源定义了我自己的控制器和 member_actions,现在我不知道如何使用 ActiveSupport::TestCase 测试它们。
任何帮助将不胜感激,谢谢。
像这样的东西:
(我使用mocha作为存根。如果不是,则需要找到另一种方法来存根身份验证,或者以管理员用户身份实际登录)
require 'test_helper'
class AdminUserControllerTest < ActionController::TestCase
setup do
# Creates a reference to the admin controller
@controller = ::Admin::UsersController.new
# Prevents checking for a valid user session (pretends we're logged in)
@controller.stubs(:authenticate_active_admin_user)
end
test "should ..." do
# ... the test ...
end
end