繁体   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