我在我的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