繁体   English   中英

如何为无模式控制器编写CanCan rspec?

[英]How to write a CanCan rspec for a modeless controller?

我有一个模型group.rb,然后是一个无模式的控制器group_invitations.rb。

GroupInvitationsController

  before_filter :find_group_by_group_id
  before_filter :authenticate_user!
  before_filter :current_ability
  authorize_resource :class => false

  def current_ability
    @current_ability ||= Ability.new(current_user, @group)
  end

当我为此编写一个rspec时:

  it "should be able to create" do
    ability = Ability.new(nil)
    ability.should be_able_to(:create, GroupInvitation.new)
  end

rspec然后出现以下错误:

NameError:未初始化的常量GroupInvitation

如何设置rspec来测试此无模式控制器? 谢谢

您需要调用@ability.should be_able_to(:create, :group_invitation) 您可以在文档中阅读有关使用无模型控制器的授权内容

这是相关的部分:

class ToolsController < ApplicationController
  authorize_resource :class => false
  def show
    # automatically calls authorize!(:show, :tool)
  end
end

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM