Skip to content

Commit

Permalink
Sign out
Browse files Browse the repository at this point in the history
  • Loading branch information
mhartl committed Aug 26, 2010
1 parent 798463f commit 0704df5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ def create
end

def destroy
sign_out
redirect_to root_path
end
end
5 changes: 5 additions & 0 deletions app/helpers/sessions_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ def signed_in?
!current_user.nil?
end

def sign_out
cookies.delete(:remember_token)
self.current_user = nil
end

private

def user_from_remember_token
Expand Down
9 changes: 9 additions & 0 deletions spec/controllers/sessions_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,13 @@
end
end
end

describe "DELETE 'destroy'" do
it "should sign a user out" do
test_sign_in(Factory(:user))
delete :destroy
controller.should_not be_signed_in
response.should redirect_to(root_path)
end
end
end
4 changes: 4 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
# Emulate initializer set_clear_dependencies_hook in
# railties/lib/rails/application/bootstrap.rb
ActiveSupport::Dependencies.clear

def test_sign_in(user)
controller.current_user = user
end
end
end

Expand Down

0 comments on commit 0704df5

Please sign in to comment.