diff options
author | jessib <jessib@riseup.net> | 2013-08-27 11:22:52 -0700 |
---|---|---|
committer | jessib <jessib@riseup.net> | 2013-08-27 11:22:52 -0700 |
commit | e481b8cbc05a858674a59ef36d695973622f6b3a (patch) | |
tree | 8a20143ce831d71076a8c3913664b3a67742ed6b /users/test/support | |
parent | 441db4736e0cd003caf9c8f7b3fbdb1ffa72b969 (diff) | |
parent | fdf9c5f9ea605020ea371de8e221efe8e5d5ba32 (diff) |
Merge pull request #72 from azul/feature/token-based-auth
Feature: Token based auth
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 | 5 |
2 files changed, 10 insertions, 4 deletions
diff --git a/users/test/support/auth_test_helper.rb b/users/test/support/auth_test_helper.rb index 555b5db..47147fc 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 = 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 end @@ -37,6 +38,12 @@ module AuthTestHelper end end + protected + + def header_for_token_auth + @token = find_record(:token, :user => @current_user) + 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..5bccb66 100644 --- a/users/test/support/stub_record_helper.rb +++ b/users/test/support/stub_record_helper.rb @@ -7,9 +7,8 @@ module StubRecordHelper # If no record is given but a hash or nil will create a stub based on # that instead and returns the stub. # - def find_record(factory, attribs_hash = {}) - attribs_hash = attribs_hash.reverse_merge(:id => Random.rand(10000).to_s) - record = stub_record factory, attribs_hash + def find_record(factory, record_or_attribs_hash = {}) + record = stub_record factory, record_or_attribs_hash, true klass = record.class finder = klass.respond_to?(:find_by_param) ? :find_by_param : :find klass.stubs(finder).with(record.to_param.to_s).returns(record) |