1 ENV["RAILS_ENV"] = "test"
2 unless ENV["NO_COVERAGE_TEST"]
5 require 'simplecov-rcov'
6 class SimpleCov::Formatter::MergedFormatter
8 SimpleCov::Formatter::HTMLFormatter.new.format(result)
9 SimpleCov::Formatter::RcovFormatter.new.format(result)
12 SimpleCov.formatter = SimpleCov::Formatter::MergedFormatter
15 add_filter 'initializers/secret_token'
16 add_filter 'initializers/omniauth'
19 $stderr.puts "SimpleCov unavailable (#{e}). Proceeding without."
23 require File.expand_path('../../config/environment', __FILE__)
24 require 'rails/test_help'
26 module ArvadosTestSupport
28 ActiveSupport::JSON.decode @response.body
31 def api_token(api_client_auth_name)
32 api_client_authorizations(api_client_auth_name).api_token
35 def auth(api_client_auth_name)
36 {'HTTP_AUTHORIZATION' => "OAuth2 #{api_token(api_client_auth_name)}"}
40 class ActiveSupport::TestCase
41 include FactoryGirl::Syntax::Methods
44 include ArvadosTestSupport
47 Thread.current[:api_client_ip_address] = nil
48 Thread.current[:api_client_authorization] = nil
49 Thread.current[:api_client_uuid] = nil
50 Thread.current[:api_client] = nil
51 Thread.current[:user] = nil
55 def restore_configuration
56 # Restore configuration settings changed during tests
57 $application_config.each do |k,v|
59 Rails.configuration.send (k + '='), v
64 def set_user_from_auth(auth_name)
65 client_auth = api_client_authorizations(auth_name)
66 Thread.current[:api_client_authorization] = client_auth
67 Thread.current[:api_client] = client_auth.api_client
68 Thread.current[:user] = client_auth.user
72 self.request.headers["Accept"] = "text/json"
75 def authorize_with api_client_auth_name
76 authorize_with_token api_client_authorizations(api_client_auth_name).api_token
79 def authorize_with_token token
81 t = t.api_token if t.respond_to? :api_token
82 ArvadosApiToken.new.call("rack.input" => "",
83 "HTTP_AUTHORIZATION" => "OAuth2 #{t}")
87 class ActionController::TestCase
92 def check_counter action
95 assert_equal 1, 2, "Multiple actions in functional test"
99 [:get, :post, :put, :patch, :delete].each do |method|
100 define_method method do |action, *args|
107 class ActionDispatch::IntegrationTest
109 Thread.current[:api_client_ip_address] = nil
110 Thread.current[:api_client_authorization] = nil
111 Thread.current[:api_client_uuid] = nil
112 Thread.current[:api_client] = nil
113 Thread.current[:user] = nil
117 # Ensure permissions are computed from the test fixtures.
118 User.invalidate_permissions_cache