Commit 5e0a8ccb

mo khan <mo@mokhan.ca>
2014-08-07 00:12:09
create action to logout.
1 parent 984c3f6
Changed files (3)
app/controllers/sessions_controller.rb
@@ -13,6 +13,11 @@ class SessionsController < ApplicationController
     end
   end
 
+  def destroy
+    cookies.delete(:cookie_monster)
+    redirect_to root_path
+  end
+
   private
 
   def session_params
config/routes.rb
@@ -33,7 +33,7 @@ Cake::Application.routes.draw do
   end
   get 'tags/:id' => 'creation_tags#show'
 
-  resources :sessions, only: [:new, :create]
+  resources :sessions, only: [:new, :create, :destroy]
 
   # /search
   get "search" => 'search#index'
spec/controllers/sessions_controller_spec.rb
@@ -42,4 +42,19 @@ describe SessionsController do
       end
     end
   end
+
+  describe "#destroy" do
+    before :each do
+      request.cookies[:cookie_monster] = SecureRandom.uuid
+      delete :destroy, id: "me"
+    end
+
+    it "removes the cookie" do
+      expect(cookies[:cookie_monster]).to be_nil
+    end
+
+    it "redirects to the homepage" do
+      expect(response).to redirect_to(root_path)
+    end
+  end
 end