2013-02-24 57 views
0

我有一個model.rb模型,然後是一個無模式的控制器group_invitations.rb。如何爲無模式控制器編寫CanCan rspec?

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的測試這種無模式控制器?謝謝

回答

1

您需要致電@ability.should be_able_to(:create, :group_invitation)。您可以閱讀documentation中使用無模型控制器時的授權內容。

這是相關部分:

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