ActiveAdmin/Rspec-ActionView::Template::Error(未定义的方法`action_methods';用于nil:NilClass)
我最近将我的测试从Cucumber/Capybara转换为Rspec/Capybara。我正在使用ActiveAdmin。当我用Cucumber对ActiveAdmin运行测试时,测试运行,一切都通过了。当我使用Rspec运行测试时,我收到:ActiveAdmin/Rspec-ActionView::Template::Error(未定义的方法`action_methods';用于nil:NilClass),rspec,activeadmin,Rspec,Activeadmin,我最近将我的测试从Cucumber/Capybara转换为Rspec/Capybara。我正在使用ActiveAdmin。当我用Cucumber对ActiveAdmin运行测试时,测试运行,一切都通过了。当我使用Rspec运行测试时,我收到: Rendered /home/vagrant/.rvm/gems/ruby-2.0.0-p451/bundler/gems/active_admin-d11c0a56504a/app/views/active_admin/resource/index.ht
Rendered /home/vagrant/.rvm/gems/ruby-2.0.0-p451/bundler/gems/active_admin-d11c0a56504a/app/views/active_admin/resource/index.html.arb (210.6ms)
Completed 500 Internal Server Error in 244ms
ActionView::Template::Error (undefined method `action_methods' for nil:NilClass):
1: insert_tag renderer_for(:index)
authlogic (3.4.2) lib/authlogic/controller_adapters/abstract_adapter.rb:63:in `method_missing'
/home/vagrant/.rvm/gems/ruby-2.0.0-p451/bundler/gems/active_admin-d11c0a56504a/lib/active_admin/resource/action_items.rb:55:in `block in add_default_action_items'
/home/vagrant/.rvm/gems/ruby-2.0.0-p451/bundler/gems/active_admin-d11c0a56504a/lib/active_admin/views/action_items.rb:9:in `instance_exec'
/home/vagrant/.rvm/gems/ruby-2.0.0-p451/bundler/gems/active_admin-d11c0a56504a/lib/active_admin/views/action_items.rb:9:in `block (2 levels) in build'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:31:in `block in build_tag'
arbre (1.0.1) lib/arbre/context.rb:92:in `with_current_arbre_element'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:49:in `with_current_arbre_element'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:26:in `build_tag'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:39:in `insert_tag'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:14:in `span'
这只是十行回溯。它实际上要大得多。让我知道我是否应该粘贴它
导致此错误的rspec中有什么不同之处
我正在使用rspec(2.14.1)、activeadmin(master)、ruby(2.0)、rails(4.1.1)
谢谢
更新
这是我的activeadmin资源:
ActiveAdmin.register UserPermission, :as => 'Support User' do
config.batch_actions = false
config.clear_action_items!
config.filters = false
actions :new, :create, :index, :destroy
action_item only: [:index] do
link_to 'Add Support User', new_admin_support_user_path
end
controller do
def scoped_collection
UserPermission.where(permission: 'support')
end
def destroy
begin
permission = UserPermission.find_by_id_and_permission!(
params[:id], UserPermission::SUPPORT)
permission.destroy if permission.present?
redirect_to admin_support_users_path, notice: 'Support user removed.'
rescue ActiveRecord::RecordNotFound
redirect_to admin_support_users_path, alert: 'Support user not found.'
end
end
def create
user = User.find_by_email(params[:email])
if user
UserPermission.create(:user_id => user.id,
:permission => UserPermission::SUPPORT,
:creator => current_user)
redirect_to admin_support_users_path, notice: 'Support user added.'
else
redirect_to new_admin_support_user_path, alert: 'User not found'
end
end
end
form partial: "form"
index :download_links => false do
column :email do |permission|
permission.user.email
end
column :created_by do |permission|
if permission.created_by.present?
u = User.find_by_id(permission.created_by)
u.email
end
end
column :created_at
actions
end
menu :parent => 'Users', :priority => 1
end
您是否在AA车型中使用
默认\u操作
,或操作
?
ActiveAdmin 1.x中不再提供默认操作。使用
操作
。我终于能够回到这个问题上来并解决它。要准确地指出错误所说的有点困难,但错误是由多种因素造成的
actions defaults: false do |permission|
link_to 'Delete', admin_support_user_path(permission), :method => :delete
end
这很有效。然而,我仍然不明白为什么只有rspec有这个问题。我使用的是默认操作。我将其更改为actions,但仍收到上述错误。不过,这是朝着正确方向迈出的一步,因为删除默认\u操作/操作至少会导致我的一些测试通过。另一方面,我不想删除该行。您是否重新启动了本地web服务器?不确定我是否清除了上面的内容,但此错误仅发生在rspec中。这一页呈现得很完美。测试使用cucumber正确运行。只有在rspec中我才收到这个错误。rspec中会导致此错误的不同之处是什么?