2013-04-13 62 views
0

我有一个从ApplicationController继承的基本管理控制器。为了测试Admin::BaseController之前的过滤器,我在这个规范中创建了一个匿名控制器。测试子应用程序控制器

require 'spec_helper' 

describe Admin::BaseController do 

    it { should be_a(ApplicationController) } 

    controller do 
    def index 
     render :text => '' 
    end 
    end 

    context 'when current user is not an admin' do 
    it 'redirects to root path' do 
     get :index 
     response.should redirect_to(root_path) 
    end 
    end 
end 

但是,当我提出一个请求index行动,它并不过滤器之前Admin::BaseController调用。

当我在ApplicationController而不是Admin::BaseController中定义该筛选器并运行测试时,它可以工作。显然这个匿名控制器继承自ApplicationController。我怎样才能改变这种行为?

回答

相关问题