2010-11-25 7 views
0

私はログインにauthlogicを使用しています。rspecとwebratでログアウトするための統合テストを作成しようとしています。webrat、Rails with Authlogicでのログアウトテストに失敗しました

私が見ている問題は、私がクリックすると私とは異なる動作をするようです。だから、ブラウザをクリックしているときにログインしてログアウトすることはできますが、私たちはログアウトできないようです。私はあなたがログインしている場合にのみログアウトリンクを表示するので、私はこれを診断しますが、ログアウトをクリックした後もまだwebratによって見つかっています。

は、ここに私のテストコードです私のroutes.rbを

map.resources :users                                              
    map.resources :user_sessions 
    map.login '/login', :controller => 'user_sessions', :action => 'new' 
    map.logout '/logout', :controller => 'user_sessions', :action => 'destroy' 

から

describe "when not signed in" do 
    it "should have a sign in link" do 
     visit root_path   
     response.should have_tag("a[href=?]", login_path, "Log In") 
    end       
    end 

    describe "when signed in" do 
    before :each do    
     @user = Factory(:user) 
     visit login_path   
     fill_in :user_session_email, :with => @user.email 
     fill_in :user_session_password, :with => @user.password 
     click_button 
    end 

    it "should have a log out button" do 
     visit root_path   
     response.should have_tag("a[href=?]", logout_path, "Log Out") 
    end 

    # This is the test that's failing                                           
    it "we should be able to log out" do 
     visit root_path 
     click_link /log out/i 
     response.should render_template('merchant_pages/home') 
     #this next line is the one that fails 
     #I've played around with this, and the log out link is still there 
     response.should have_tag("a[href=?]", login_path, "Log In") 
    end 
    end 

数行私はuser_sessions_controllerから

<ul class="navigation round"> 
    <li><%= link_to("Log In", login_path) unless current_user %></li> 
    <li><%= link_to("Log Out", logout_path) if current_user %></li> 
    </ul> 

を探していたリンク

def destroy 
    current_user_session.destroy 
    flash[:notice] = "Logout successful!" 
    redirect_to root_url 
    end 
012私は手動でログアウト時

authlogic (2.1.6) 
rails (2.3.8) 
rake (0.8.7) 
rspec (1.3.0) 
rspec-core (2.0.1) 
rspec-expectations (2.0.1) 
rspec-mocks (2.0.1) 
rspec-rails (1.3.2) 
webrat (0.7.2) 

のでapplication_controller

def current_user_session 
    return @current_user_session if defined?(@current_user_session) 
    @current_user_session = UserSession.find 
end 

def current_user 
    return @current_user if defined?(@current_user) 
    @current_user = current_user_session && current_user_session.record 
end 

関連する宝石のバージョンから

、結論で、私は、ホームページに移動し、私は私に利用できるリンクでログを持っていますログアウトリンクはありません。上記のテストでwebratを通過すると、ログインしなくてもログアウトリンクが表示され、まだサインインしていることを示します。

+0

バグは 'click_link/logout/i'行にあると思います。代わりに 'click_link"ログアウト "を使うべきでしょうか? – tjeden

+0

私はそれを試みました。説明したのと同じ動作です。 –

答えて

1

これは、データベースセッションストアではなくクッキーセッションストアを使用します。 config/initializers/session_store.rbを参照してください。

昨日、開発中のプロジェクトを2.3.5から2.3.8に移植し始めました。 2.3.5では、すべての仕様と機能が緑色でした。 Railsのバージョンを2.3.8に変更した後、キュウリのいくつかのステップが失敗し始めました。この手順は、サインアウトできないこと(正確にここで説明する内容)とフラッシュ[:通知]が失われたことに関連していました。このプロジェクトは、別のプロジェクトのファイルをクリーンスレートのRailsプロジェクトにコピーすることによって作成されました。このプロセスでは、セッションの移行はコピーされましたが、session_store.rbは実際にデータベースを使用するように更新されませんでした。

session_store.rbで "ActionController :: Base.session_store =:active_record_store"のコメントを外すと、キュウリのステップが渡り始めました。

+0

私は同じエラーが発生しています - アクティブなレコードセッションストアを使用し続け、セッションでキュウリの作業を続けるのは良いことです。 –

関連する問題