我在我的Rails项目上使用activeadmin,我想知道如何对它进行测试。我在网上查了一下,但没有关于它的文档。 我有一个设置资源,我禁用了创建一个新的或删除它的可能性。使用activeadmin进行rails测试
我想知道如何测试这些路线不存在或另一种方式来确保它无法访问。 在我实际的,虽然我试图断言这个页面是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(NOT RSPEC)
如果您从该行删除:new操作:all,但:[:new,:destroy]您仍然得到相同的错误吗?你有没有试过,而不是assert_response ...做这样的值(回应).must_respond_with 404 – MilesStanfield 2015-08-13 04:55:46