2012-02-29 5 views
5

이상한 문제가 있습니다. 응용 프로그램 컨트롤러에는 을 사용하여 인증을 요구하는 before_filter 세트가 있으며 로그인 페이지로 필요한 경우 리디렉션됩니다.rspec은 skip_before_filter를 무시합니까?

라이브러리 컨트롤러에서 우리는 이것을 건너 뜁니다. before_filter.

skip_before_filter :authenticate_user!, :only => :show 

우리가 capybara 및 테스트가 실패 rspec 간단한 기능 테스트를 실행

.

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

이 필터를 건너 뛰지 않은 것처럼 보입니다. 페이지 내용은 로그인 페이지입니다.

rails server으로 실행하면 문제가 없습니다.

왜 이런 식으로 행동하는지 또는이 문제를 해결하기 위해 무엇을 찾아야할까요?

UPDATE :

그것은이는 리눅스를 사용하여 발생하는 것을 추가 가치가있을 수도 있습니다. 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 
application_controller합니다 (set_i18n_locale_from_url없이)처럼 보인다

:

class ApplicationController < ActionController::Base 
    protect_from_forgery 
    before_filter :set_i18n_locale_from_url, :authenticate_user! 
end 

경로 :

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 
+0

내가이 똑같은 행동을보고하고있다. –

답변

3

내가 F를 추측 가장 먼저 할 일은 "visit '/ ko/library/computers'"가 실제로 컨트롤러에서 show 액션을 호출하는지 여부를 확인하는 것입니다.

visit library_path('computers') 

다음 쇼의 내부에 일부 디버거 텍스트 (풋 'ㅋ')를 던져 : 당신이 쇼의 조치를 액세스하는 편안한 경로를 사용하는 경우 뭔가처럼 보이는, 그래서 현재의 URL 경로 대신에 그것을 사용 메서드를 사용하여 테스트하고 있습니다. 어쩌면 엄격한 경로를 호출하면 before_filters를 우회하여 이상한 일을 할 수 있습니다.

업데이트 : 컨트롤러가 더의 ID로 '컴퓨터'를 해석 할 수 있습니다처럼

는 보지 않는다.

resources :libraries do 
    member do 
    get :computers 
    end 
end 

을 그리고 컨트롤러에 추가 : 당신이 당신의 도서관 자원에 구성원 경로를 추가하면 무엇을 당신의 경로 내부 컴퓨터

+0

좋아, 우리는 이것을 시도했다. 같은 결과. 테스트가 실패했습니다. show 메서드 내에서 디버거 출력이 실행되지 않습니다. – NielsH

+0

컨트롤러 코드를 게시 할 수 있습니까? –

+0

좋아, 원래 게시물을 업데이트했습니다. – NielsH

1

I을 :

def computers 
    @categories = Category.all 
end 

을 변경하면 사용 skip_before_filter 카테고리 모델과 관련하여 공장 및 다른 현지화와 관련이 있다고 생각하십시오. 아마도 리눅스에서는 다른 기본 로케일을 사용하기 때문에 실패합니다.

는 내가 인증을 위해 before_filter를 제거하고 대부분의 테스트는 통과하지만이 발생

1) Categories when user requests the category page 
     GET /en/library/computers 
     should get only english articles within the category computers 
    Failure/Error: page.should have_content(@english_articles[0].title) 
     expected there to be content "article 1 en" in "Bibliothek\nAdmin\nSign up\nLogin\n\n\n\n\n\n\n\n\nHome\n>\n\n\nLibrary\n>\n\n\Computer\n>\n\nThe spine\n\n\n\n\n\n\n\n\n\nComputer\n\n\n\n\n\n\n\n\n\n\n\n\nComputer\n\n\n\narticle 6 de\n\ncontent_6\n\n\narticle 7 de\n\ncontent_7\n\n\narticle 8 de\n\ncontent_8\n\n\narticle 9 de\n\ncontent_9\n\n\narticle 10 de\n\ncontent_10" 
    # ./spec/requests/categories_spec.rb:20:in `block (4 levels) in <top (required)>' 
관련 문제