diff options
author | Azul <azul@leap.se> | 2013-08-27 11:14:30 +0200 |
---|---|---|
committer | Azul <azul@leap.se> | 2013-08-27 14:57:44 +0200 |
commit | e60ee749cab0f80cf23ca57e28c7de6d1b3a395b (patch) | |
tree | 9c647de3952d8f8fe78fc4fcb06de0d504c436d5 /users/test/support | |
parent | 7ad6d054d72d3c76098f689e4e7890265a3604c8 (diff) |
basic testing for token based auth in tests
Diffstat (limited to 'users/test/support')
-rw-r--r-- | users/test/support/auth_test_helper.rb | 9 | ||||
-rw-r--r-- | users/test/support/stub_record_helper.rb | 2 |
2 files changed, 9 insertions, 2 deletions
diff --git a/users/test/support/auth_test_helper.rb b/users/test/support/auth_test_helper.rb index 555b5db..ab6b1ac 100644 --- a/users/test/support/auth_test_helper.rb +++ b/users/test/support/auth_test_helper.rb @@ -13,8 +13,9 @@ module AuthTestHelper if user_or_method_hash.respond_to?(:reverse_merge) user_or_method_hash.reverse_merge! :is_admin? => false end - @current_user = stub_record(:user, user_or_method_hash, true) + @current_user = find_record(:user, user_or_method_hash) request.env['warden'] = stub :user => @current_user + request.env['HTTP_AUTHORIZATION'] = header_for_token_auth return @current_user end @@ -37,6 +38,12 @@ module AuthTestHelper end end + protected + + def header_for_token_auth + @token = find_record(:token, :user_id => @current_user.id) + ActionController::HttpAuthentication::Token.encode_credentials @token.id + end end class ActionController::TestCase diff --git a/users/test/support/stub_record_helper.rb b/users/test/support/stub_record_helper.rb index 8aa1973..b3460d2 100644 --- a/users/test/support/stub_record_helper.rb +++ b/users/test/support/stub_record_helper.rb @@ -1,7 +1,7 @@ module StubRecordHelper # - # We will stub find_by_param or find_by_id to be called on klass and + # We will stub find_by_param or find to be called on klass and # return the record given. # # If no record is given but a hash or nil will create a stub based on |