我正在我的Rails项目中使用activeadmin,想知道如何对其进行测试。我在互联网上查找了一些资料,但没有相关文档。
我有一个设置资源,并禁用了创建新资源或删除它的可能性。
我想知道如何测试这些路由是否存在,或者有其他方法确保它无法访问。 在我的实际尝试中,我试图断言此页面为404,但测试似乎会抛出以下错误(这正是我试图测试的内容!!!):
我的activeadmin文件:
(注:该段为原文,无需翻译)
我想知道如何测试这些路由是否存在,或者有其他方法确保它无法访问。 在我的实际尝试中,我试图断言此页面为404,但测试似乎会抛出以下错误(这正是我试图测试的内容!!!):
ActionController::UrlGenerationError: No route matches {:action=>"new", :controller=>"admin/settings"}
我不使用Rspec而是使用Rails自带的Minitest。
感谢您的帮助!我的activeadmin文件:
ActiveAdmin.register Setting do
actions :all, except: [:new, :destroy]
…
end
我的测试:
require 'test_helper'
class Admin::SettingsControllerTest < ActionController::TestCase
include Devise::TestHelpers
setup :initialize_settings
test 'should throw 404 if trying to access new action' do
get :new
assert_response 404
end
def initialize_settings
sign_in users(:one)
end
end
我的项目:
- Rails 4.2
- Ruby 2.2.0
- Minitest(不是RSpec)
(注:该段为原文,无需翻译)