require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
+require 'mocha/mini_test'
class ActiveSupport::TestCase
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in
Thread.current[:arvados_api_token] = auth['api_token']
end
- def teardown
+ teardown do
Thread.current[:arvados_api_token] = nil
+ Thread.current[:user] = nil
Thread.current[:reader_tokens] = nil
- super
+ # Diagnostics suite doesn't run a server, so there's no cache to clear.
+ Rails.cache.clear unless (Rails.env == "diagnostics")
+ # Restore configuration settings changed during tests
+ $application_config.each do |k,v|
+ if k.match /^[^.]*$/
+ Rails.configuration.send (k + '='), v
+ end
+ end
end
end
module ClassMethods
@@api_fixtures = {}
- def api_fixture(name)
+ def api_fixture(name, *keys)
# Returns the data structure from the named API server test fixture.
@@api_fixtures[name] ||= \
begin
'test', 'fixtures', "#{name}.yml")
YAML.load(IO.read(path))
end
+ keys.inject(@@api_fixtures[name]) { |hash, key| hash[key] }
end
end
- def api_fixture name
- self.class.api_fixture name
+ def api_fixture(name, *keys)
+ self.class.api_fixture(name, *keys)
+ end
+
+ def find_fixture(object_class, name)
+ object_class.find(api_fixture(object_class.to_s.pluralize.underscore,
+ name, "uuid"))
end
end
end
end
+class ActionController::TestCase
+ setup do
+ @counter = 0
+ end
+
+ def check_counter action
+ @counter += 1
+ if @counter == 2
+ assert_equal 1, 2, "Multiple actions in functional test"
+ end
+ end
+
+ [:get, :post, :put, :patch, :delete].each do |method|
+ define_method method do |action, *args|
+ check_counter action
+ super action, *args
+ end
+ end
+end
+
if ENV["RAILS_ENV"].eql? 'test'
ApiServerForTests.run
end