Resolving application_controller.rb merge conflicts, tests pass.
[arvados.git] / services / api / test / test_helper.rb
1 ENV["RAILS_ENV"] = "test"
2 require File.expand_path('../../config/environment', __FILE__)
3 require 'rails/test_help'
4
5 class ActiveSupport::TestCase
6   # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
7   #
8   # Note: You'll currently still have to declare fixtures explicitly in integration tests
9   # -- they do not yet inherit this setting
10   fixtures :all
11
12   teardown do
13     Thread.current[:api_client_ip_address] = nil
14     Thread.current[:api_client_authorization] = nil
15     Thread.current[:api_client_uuid] = nil
16     Thread.current[:api_client] = nil
17     Thread.current[:user] = nil
18   end
19
20   def expect_json
21     self.request.headers["Accept"] = "text/json"
22   end
23
24   def json_response
25     @json_response ||= ActiveSupport::JSON.decode @response.body
26   end
27
28   def authorize_with(api_client_auth_name)
29     ArvadosApiToken.new.call ({"rack.input" => "", "HTTP_AUTHORIZATION" => "OAuth2 #{api_client_authorizations(api_client_auth_name).api_token}"})
30   end
31
32   # Add more helper methods to be used by all tests here...
33 end
34
35 class ActionDispatch::IntegrationTest
36
37   teardown do
38     Thread.current[:api_client_ip_address] = nil
39     Thread.current[:api_client_authorization] = nil
40     Thread.current[:api_client_uuid] = nil
41     Thread.current[:api_client] = nil
42     Thread.current[:user] = nil
43   end
44
45   def auth auth_fixture
46     {'HTTP_AUTHORIZATION' => "OAuth2 #{api_client_authorizations(auth_fixture).api_token}"}
47   end
48 end
49
50 # Ensure permissions are computed from the test fixtures.
51 User.invalidate_permissions_cache