Convert joins to subqueries to fix duplicates in owned_items
[arvados.git] / services / api / test / test_helper.rb
index 9955a3500ffe9830c41974679954e6956c6f4f21..286cf66f28f240f00ea9aaf98bbb0ce5c13e7b8e 100644 (file)
@@ -9,13 +9,43 @@ class ActiveSupport::TestCase
   # -- they do not yet inherit this setting
   fixtures :all
 
+  teardown do
+    Thread.current[:api_client_ip_address] = nil
+    Thread.current[:api_client_authorization] = nil
+    Thread.current[:api_client_uuid] = nil
+    Thread.current[:api_client] = nil
+    Thread.current[:user] = nil
+  end
+
   def expect_json
     self.request.headers["Accept"] = "text/json"
   end
 
+  def json_response
+    @json_response ||= ActiveSupport::JSON.decode @response.body
+  end
+
   def authorize_with(api_client_auth_name)
     self.request.env['HTTP_AUTHORIZATION'] = "OAuth2 #{api_client_authorizations(api_client_auth_name).api_token}"
   end
 
   # Add more helper methods to be used by all tests here...
 end
+
+class ActionDispatch::IntegrationTest
+
+  teardown do
+    Thread.current[:api_client_ip_address] = nil
+    Thread.current[:api_client_authorization] = nil
+    Thread.current[:api_client_uuid] = nil
+    Thread.current[:api_client] = nil
+    Thread.current[:user] = nil
+  end
+
+  def auth auth_fixture
+    {'HTTP_AUTHORIZATION' => "OAuth2 #{api_client_authorizations(auth_fixture).api_token}"}
+  end
+end
+
+# Ensure permissions are computed from the test fixtures.
+User.invalidate_permissions_cache