Ruby on rails 测试子应用程序控制器
我有一个从Ruby on rails 测试子应用程序控制器,ruby-on-rails,ruby-on-rails-3,rspec,Ruby On Rails,Ruby On Rails 3,Rspec,我有一个从ApplicationController继承的基本管理控制器。为了测试Admin::BaseController中的before过滤器,我在这个规范中创建了一个匿名控制器 require 'spec_helper' describe Admin::BaseController do it { should be_a(ApplicationController) } controller do def index render :text =>
ApplicationController
继承的基本管理控制器。为了测试Admin::BaseController
中的before过滤器,我在这个规范中创建了一个匿名控制器
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
中的before过滤器
当我在
ApplicationController
而不是Admin::BaseController
中定义该过滤器并运行测试时,它就工作了。显然,此匿名控制器继承自ApplicationController
。如何改变这种行为?我在这里找到了答案
成功了
controller(Admin::BaseController) do
def index
render :text => ''
end
end