私はログインに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を通過すると、ログインしなくてもログアウトリンクが表示され、まだサインインしていることを示します。
バグは 'click_link/logout/i'行にあると思います。代わりに 'click_link"ログアウト "を使うべきでしょうか? – tjeden
私はそれを試みました。説明したのと同じ動作です。 –