2012-02-29 11 views
5

私たちは奇妙な問題を抱えています。アプリケーションコントローラでは、deviseを使用して認証が必要なbefore_filterセットがあり、必要に応じてログインページにリダイレクトされます。rspecはskip_before_filterを無視しますか?

ライブラリコントローラでは、これをスキップします。before_filter

skip_before_filter :authenticate_user!, :only => :show 

我々はテストが失敗したcapybararspecとシンプルな機能テストを実行します。

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

このフィルタをスキップしないようです。ページの内容はログインページの内容です。

rails serverでこれを実行すると問題なく動作します。

このように動作する理由、またはこれを解決するために何を探す必要があるのでしょうか?

UPDATE:

これが唯一の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 

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 '/ en/library/computers'"が実際にあなたのコントローラでshowアクションを呼び出すかどうかを確認することです。

visit library_path('computers') 

次はあなたのショーの中にいくつかのデバッガテキスト(プット「何とか」)を投げる:あなたはshowアクションにアクセス安らかなパスを使用している場合、それは何かのように見えるので、あなたの現在のURLパスの代わりにそれを使いますあなたがテストしていることを確認して、それが来ていることを確認してください。たぶん厳密なパスを呼び出すことによって、before_filtersをバイパスして変なことが起こるかもしれません。

UPDATE:あなたのコントローラが何のIDとしてのコンピュータ」を解釈することがありますように

が見えません。あなたのルートの中で、あなたがあなたのライブラリにリソースメンバーのルートを追加した場合:

resources :libraries do 
    member do 
    get :computers 
    end 
end 

そして、あなたのコントローラアドインで:

def computers 
    @categories = Category.all 
end 

をし、使用するskip_before_filter変更:コンピュータ

+0

さて、これを試しました。同じ結果。テストは失敗しています。 showメソッド内のデバッガ出力は実行されません。 – NielsH

+0

コントローラコードを投稿できますか? –

+0

さて、元の投稿を更新しました。 – NielsH

1

I私たちがカテゴリモデルのために持っている工場と異なるローカリゼーションとは関係があると思います。おそらく、Linuxの下では、別のデフォルトロケールを使用するため、失敗するのです。

私は認証のために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)>' 
関連する問題