summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--users/app/controllers/controller_extension/token_authentication.rb2
-rw-r--r--users/app/models/token.rb4
-rw-r--r--users/test/functional/test_helpers_test.rb2
-rw-r--r--users/test/support/auth_test_helper.rb4
4 files changed, 8 insertions, 4 deletions
diff --git a/users/app/controllers/controller_extension/token_authentication.rb b/users/app/controllers/controller_extension/token_authentication.rb
index 82df314..3e2816d 100644
--- a/users/app/controllers/controller_extension/token_authentication.rb
+++ b/users/app/controllers/controller_extension/token_authentication.rb
@@ -5,7 +5,7 @@ module ControllerExtension::TokenAuthentication
authenticate_with_http_token do |token_id, options|
@token = Token.find(token_id)
end
- User.find_by_param(@token.user_id) if @token
+ @token.user if @token
end
def logout
diff --git a/users/app/models/token.rb b/users/app/models/token.rb
index cc62778..514b97f 100644
--- a/users/app/models/token.rb
+++ b/users/app/models/token.rb
@@ -6,6 +6,10 @@ class Token < CouchRest::Model::Base
validates :user_id, presence: true
+ def user
+ User.find(self.user_id)
+ end
+
def initialize(*args)
super
self.id = SecureRandom.urlsafe_base64(32).gsub(/^_*/, '')
diff --git a/users/test/functional/test_helpers_test.rb b/users/test/functional/test_helpers_test.rb
index d1bdb64..9bd01ad 100644
--- a/users/test/functional/test_helpers_test.rb
+++ b/users/test/functional/test_helpers_test.rb
@@ -21,7 +21,7 @@ class TestHelpersTest < ActionController::TestCase
def test_login_stubs_token
login
assert @token
- assert_equal @current_user.id, @token.user_id
+ assert_equal @current_user, @token.user
end
def test_login_adds_token_header
diff --git a/users/test/support/auth_test_helper.rb b/users/test/support/auth_test_helper.rb
index ab6b1ac..47147fc 100644
--- a/users/test/support/auth_test_helper.rb
+++ b/users/test/support/auth_test_helper.rb
@@ -13,7 +13,7 @@ module AuthTestHelper
if user_or_method_hash.respond_to?(:reverse_merge)
user_or_method_hash.reverse_merge! :is_admin? => false
end
- @current_user = find_record(:user, user_or_method_hash)
+ @current_user = stub_record(:user, user_or_method_hash)
request.env['warden'] = stub :user => @current_user
request.env['HTTP_AUTHORIZATION'] = header_for_token_auth
return @current_user
@@ -41,7 +41,7 @@ module AuthTestHelper
protected
def header_for_token_auth
- @token = find_record(:token, :user_id => @current_user.id)
+ @token = find_record(:token, :user => @current_user)
ActionController::HttpAuthentication::Token.encode_credentials @token.id
end
end