ActiveAdmin / Rspec - ActionView :: Template :: Error(未定义的方法`action_methods' for nil:NilClass)

时间:2014-05-28 18:35:37

标签: 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.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

2 个答案:

答案 0 :(得分:0)

您是否在AA模型中使用default_actionsactions? ActiveAdmin 1.x中不再提供default_actions。请改用actions

答案 1 :(得分:0)

我终于能够回到这一点并弄明白了。确切地指出错误所说的内容有点困难,但错误是由于各种因素的结合。

  1. config.clear_action_items! - 这删除了我的所有控制器操作(编辑,显示,新建,创建......)。
  2. actions:new,:create,:index,:destroy - 这创建了我想要的唯一控制器操作。
  3. 索引块中的操作(抛出错误) - 这是尝试呈现默认的编辑,显示和销毁操作,这些操作不会全部存在,从而导致异常。
  4. 我的解决方法是不要尝试渲染那些丢失的动作。而不是行动,我现在有:

    actions defaults: false do |permission|
      link_to 'Delete', admin_support_user_path(permission), :method => :delete
    end
    

    这很有效。但是,我仍然不明白为什么只有rspec有这个问题。