summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--users/app/controllers/controller_extension/token_authentication.rb12
-rw-r--r--users/test/functional/v1/sessions_controller_test.rb13
2 files changed, 17 insertions, 8 deletions
diff --git a/users/app/controllers/controller_extension/token_authentication.rb b/users/app/controllers/controller_extension/token_authentication.rb
index 06e9e04..e1c92e7 100644
--- a/users/app/controllers/controller_extension/token_authentication.rb
+++ b/users/app/controllers/controller_extension/token_authentication.rb
@@ -7,5 +7,17 @@ module ControllerExtension::TokenAuthentication
end
User.find_by_param(@token.user_id) if @token
end
+
+ def logout
+ super
+ clear_token
+ end
+
+ def clear_token
+ authenticate_with_http_token do |token_id, options|
+ @token = Token.find(token_id)
+ @token.destroy if @token
+ end
+ end
end
diff --git a/users/test/functional/v1/sessions_controller_test.rb b/users/test/functional/v1/sessions_controller_test.rb
index 8a16997..ff9fca1 100644
--- a/users/test/functional/v1/sessions_controller_test.rb
+++ b/users/test/functional/v1/sessions_controller_test.rb
@@ -52,20 +52,18 @@ class V1::SessionsControllerTest < ActionController::TestCase
assert_equal @user.id, token.user_id
end
- test "logout should reset warden user" do
+ test "logout should reset session" do
expect_warden_logout
delete :destroy
assert_response 204
end
- test "logout should remove token" do
+ test "logout should destroy token" do
login
expect_warden_logout
- skip "TODO: implement token removal"
- assert_difference "Token.count", -1 do
- delete :destroy
- assert_response 204
- end
+ @token.expects(:destroy)
+ delete :destroy
+ assert_response 204
end
def expect_warden_logout
@@ -76,5 +74,4 @@ class V1::SessionsControllerTest < ActionController::TestCase
request.env['warden'].expects(:logout)
end
-
end