簡體   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