Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add destroy session

  • Loading branch information...
commit 282031b944d0854b31631d02ecbff42fbbe77e4e 1 parent e7056b3
@FuriKuri authored
View
2  app/controllers/sessions_controller.rb
@@ -13,5 +13,7 @@ def create
end
def destroy
+ session[:user_id] = nil
+ redirect_to login_url, notice: "Logged out"
end
end
View
17 test/functional/sessions_controller_test.rb
@@ -5,4 +5,21 @@ class SessionsControllerTest < ActionController::TestCase
get :new
assert_response :success
end
+
+ test "should login with an user" do
+ post :create, :name => 'dave', :password => 'secret'
+ assert_redirected_to books_url
+ assert_not_nil session[:user_id]
+ end
+
+ test "should not login with an incorrect user" do
+ post :create, :name => 'dave', :password => 'wrong'
+ assert_redirected_to login_url
+ end
+
+ test "should log out" do
+ login_as(:dave)
+ delete :destroy
+ assert_nil session[:user_id]
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.