Revision 16787
Added by Jean-Philippe Lang almost 8 years ago
sandbox/rails-5.1/test/test_helper.rb | ||
---|---|---|
49 | 49 |
class ActiveSupport::TestCase |
50 | 50 |
include ActionDispatch::TestProcess |
51 | 51 |
|
52 |
self.use_transactional_fixtures = true
|
|
52 |
self.use_transactional_tests = true
|
|
53 | 53 |
self.use_instantiated_fixtures = false |
54 | 54 |
|
55 | 55 |
def uploaded_test_file(name, mime) |
... | ... | |
319 | 319 |
end |
320 | 320 |
assert_equal expected_filters.size, filter_init.scan("addFilter").size, "filters counts don't match" |
321 | 321 |
end |
322 |
|
|
323 |
def process(action, http_method = 'GET', *args) |
|
324 |
parameters, session, flash = *args |
|
325 |
if args.size == 1 && parameters[:xhr] == true |
|
326 |
xhr http_method.downcase.to_sym, action, parameters.except(:xhr) |
|
327 |
elsif parameters && (parameters.key?(:params) || parameters.key?(:session) || parameters.key?(:flash)) |
|
328 |
super action, http_method, parameters[:params], parameters[:session], parameters[:flash] |
|
329 |
else |
|
330 |
super |
|
331 |
end |
|
332 |
end |
|
333 | 322 |
end |
334 | 323 |
|
335 | 324 |
class IntegrationTest < ActionDispatch::IntegrationTest |
... | ... | |
339 | 328 |
assert_nil session[:user_id] |
340 | 329 |
assert_response :success |
341 | 330 |
|
342 |
post "/login", :username => login, :password => password |
|
331 |
post "/login", :params => { |
|
332 |
:username => login, |
|
333 |
:password => password |
|
334 |
} |
|
343 | 335 |
assert_equal login, User.find(session[:user_id]).login |
344 | 336 |
end |
345 | 337 |
|
346 |
%w(get post patch put delete head).each do |http_method| |
|
347 |
class_eval %Q" |
|
348 |
def #{http_method}(path, parameters = nil, headers_or_env = nil) |
|
349 |
if headers_or_env.nil? && parameters.is_a?(Hash) && (parameters.key?(:params) || parameters.key?(:headers)) |
|
350 |
super path, parameters[:params], parameters[:headers] |
|
351 |
else |
|
352 |
super |
|
353 |
end |
|
354 |
end" |
|
355 |
end |
|
356 |
|
|
357 | 338 |
def credentials(user, password=nil) |
358 | 339 |
{'HTTP_AUTHORIZATION' => ActionController::HttpAuthentication::Basic.encode_credentials(user, password || user)} |
359 | 340 |
end |
... | ... | |
385 | 366 |
def upload(format, content, credentials) |
386 | 367 |
set_tmp_attachments_directory |
387 | 368 |
assert_difference 'Attachment.count' do |
388 |
post "/uploads.#{format}", content, {"CONTENT_TYPE" => 'application/octet-stream'}.merge(credentials) |
|
369 |
post "/uploads.#{format}", |
|
370 |
:params => content, |
|
371 |
:headers => {"CONTENT_TYPE" => 'application/octet-stream'}.merge(credentials) |
|
389 | 372 |
assert_response :created |
390 | 373 |
end |
391 | 374 |
data = response_data |
Also available in: Unified diff
Removes compatibilty for Rails 4 tests syntax.