簡體   English   中英

CanCan,如何使用無模式控制器測試rspec?

[英]CanCan, how to test an rspec with a modeless, controller?

我有一個帶OA模型的管理員控制器

class AdminController < ApplicationController

    # Sign In Required - Devise Check
    before_filter :authenticate_user!
    # CanCan
    before_filter :current_ability

  # CanCan for Non RESTful Controllers - https://github.com/ryanb/cancan/wiki/Non-RESTful-Controllers
  # We do this as there is no admin model/resouce
  authorize_resource :class => false

我無法弄清楚如何為控制器編寫規格。 我有以下幾點:

  describe 'Admin User' do

    it "should be allow admin users to view admin#index" do
      @ability_for_user_4.can :read, Admin
      get :index
      assert_template :index
    end
  end

這將失敗:未初始化的常量Admin

有任何想法嗎? 謝謝

您的規格是否以require 'spec_helper' 大多數Ruby on Rails規范都是以此為開頭的,它將把Rails環境加載到內存中。

否則,您需要創建一個模擬模型,以便Rspec知道Admin是什么。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM