Merge branch '17161-doc-system-root-token'
[arvados.git] / services / api / test / test_helper.rb
index ad5fb8e2a5ac7c3def432cc64402f8efc38ae4da..ee7dac4cd90099bb1d9b9fe17a9a781baaee5f1c 100644 (file)
@@ -62,7 +62,7 @@ class ActiveSupport::TestCase
   include ArvadosTestSupport
   include CurrentApiClient
 
-  teardown do
+  setup do
     Thread.current[:api_client_ip_address] = nil
     Thread.current[:api_client_authorization] = nil
     Thread.current[:api_client_uuid] = nil
@@ -72,6 +72,14 @@ class ActiveSupport::TestCase
     restore_configuration
   end
 
+  teardown do
+    # Confirm that any changed configuration doesn't include non-symbol keys
+    $arvados_config.keys.each do |conf_name|
+      conf = Rails.configuration.send(conf_name)
+      confirm_keys_as_symbols(conf, conf_name) if conf.respond_to?('keys')
+    end
+  end
+
   def assert_equal(expect, *args)
     if expect.nil?
       assert_nil(*args)
@@ -99,21 +107,15 @@ class ActiveSupport::TestCase
     end
   end
 
-  def confirm_keys_as_symbols(a_hash, section_name)
-    a_hash.keys.each do |k|
-      assert(k.is_a?(Symbol), "Key '#{k}' on section '#{section_name}' should be a Symbol")
-      confirm_keys_as_symbols(a_hash[k], "#{section_name}.#{k}") if a_hash[k].is_a?(Hash)
+  def confirm_keys_as_symbols(conf, conf_name)
+    assert(conf.is_a?(ActiveSupport::OrderedOptions), "#{conf_name} should be an OrderedOptions object")
+    conf.keys.each do |k|
+      assert(k.is_a?(Symbol), "Key '#{k}' on section '#{conf_name}' should be a Symbol")
+      confirm_keys_as_symbols(conf[k], "#{conf_name}.#{k}") if conf[k].respond_to?('keys')
     end
   end
 
   def restore_configuration
-    # Confirm that any changed configuration doesn't include non-symbol keys
-    $arvados_config.keys.each do |config_section_name|
-      config_section = Rails.configuration.send("#{config_section_name}")
-      if config_section.is_a?(Hash)
-        confirm_keys_as_symbols(config_section, config_section_name)
-      end
-    end
     # Restore configuration settings changed during tests
     ConfigLoader.copy_into_config $arvados_config, Rails.configuration
     ConfigLoader.copy_into_config $remaining_config, Rails.configuration
@@ -121,6 +123,7 @@ class ActiveSupport::TestCase
 
   def set_user_from_auth(auth_name)
     client_auth = api_client_authorizations(auth_name)
+    client_auth.user.forget_cached_group_perms
     Thread.current[:api_client_authorization] = client_auth
     Thread.current[:api_client] = client_auth.api_client
     Thread.current[:user] = client_auth.user