Adding missing file.
[arvados.git] / services / api / test / test_helper.rb
index 869d87f7db19f24d63743b04d410404ba4379082..e1738c3aa1fd690e041f0d58ae88f81be54350e2 100644 (file)
@@ -4,7 +4,7 @@ require 'rails/test_help'
 
 module ArvadosTestSupport
   def json_response
-    @json_response ||= ActiveSupport::JSON.decode @response.body
+    ActiveSupport::JSON.decode @response.body
   end
 
   def api_token(api_client_auth_name)
@@ -17,10 +17,6 @@ module ArvadosTestSupport
 end
 
 class ActiveSupport::TestCase
-  # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
-  #
-  # Note: You'll currently still have to declare fixtures explicitly in integration tests
-  # -- they do not yet inherit this setting
   fixtures :all
 
   include ArvadosTestSupport
@@ -33,6 +29,13 @@ class ActiveSupport::TestCase
     Thread.current[:user] = nil
   end
 
+  def set_user_from_auth(auth_name)
+    client_auth = api_client_authorizations(auth_name)
+    Thread.current[:api_client_authorization] = client_auth
+    Thread.current[:api_client] = client_auth.api_client
+    Thread.current[:user] = client_auth.user
+  end
+
   def expect_json
     self.request.headers["Accept"] = "text/json"
   end