rspec忽略skip_before_filter?

Nie*_*lsH 5 rspec devise capybara ruby-on-rails-3

我们遇到了一个奇怪的问题.在应用程序控制器中,我们有一个before_filter需要使用身份验证的集合,devise如果需要,还可以重定向到登录页面.

在我们的磁带库控制器,我们跳过这个before_filter.

skip_before_filter :authenticate_user!, :only => :show
Run Code Online (Sandbox Code Playgroud)

当我们运行简单的功能测试时capybara,rspec测试失败.

it "should get only english articles within the category 'computers'" do
    visit '/en/library/computers'
    page.should have_content('computers')
end
Run Code Online (Sandbox Code Playgroud)

看起来它不会跳过此过滤器.页面内容是登录页面.

当我们运行它时rails server它工作正常.

任何想法为什么它以这种方式行事或寻找什么来解决这个问题?

更新:

值得补充的是,这只发生在Linux上.在具有"相同"设置的MacOS 10.7下,它可以正常工作.

控制器代码:

class Library::CategoriesController < ApplicationController
  skip_before_filter :authenticate_user!, :only => [:show]

  # GET /categories/1
  # GET /categories/1.json
  def show

    @categories = Category.all
    @category = Category.find(params[:id])

    @articles = @category.articles.where(:locale => I18n.locale)
    respond_to do |format|
      format.html # show.html.erb
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

application_controller看起来像(没有set_i18n_locale_from_url):

class ApplicationController < ActionController::Base
  protect_from_forgery
  before_filter :set_i18n_locale_from_url, :authenticate_user!
end
Run Code Online (Sandbox Code Playgroud)

路线:

namespace :library do
  get '/' => 'library#index', :as => 'library'
  resources :categories, :path => '', :only => [:show]
  resources :categories, :path => '', :only => []  do
    resources :articles, :path => '', :only => [:show]
  end
end
Run Code Online (Sandbox Code Playgroud)

Chr*_*tto 3

我想您可以做的第一件事就是查看“访问'/en/library/computers'”是否实际上正在调用控制器中的显示操作。如果您使用访问 show 操作的静态路径,请使用它代替当前的 url 路径,这样它看起来像:

visit library_path('computers')
Run Code Online (Sandbox Code Playgroud)

接下来,在您正在测试的 show 方法中放入一些调试器文本(放入“blah”),并确保它出现。也许通过调用严格路径会绕过 before_filters 做一些奇怪的事情。

更新:

看起来您的控制器可能不会将“计算机”解释为 ID。在您的路由中,如果将成员路由添加到您的库资源会怎样:

resources :libraries do
  member do
    get :computers
  end
end
Run Code Online (Sandbox Code Playgroud)

在你的控制器中添加:

def computers
  @categories = Category.all
end
Run Code Online (Sandbox Code Playgroud)

并将您的skip_before_filter更改为使用:computers