Skip to content

Commit e11a62a

Browse files
committed
Merge pull request rails#27289 from matthewd/fixture-file-module
Only move fixture_file_upload to IntegrationTest
1 parent 5e50daa commit e11a62a

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

actionpack/lib/action_dispatch/testing/integration.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class Session
140140
DEFAULT_HOST = "www.example.com"
141141

142142
include Minitest::Assertions
143-
include RequestHelpers, Assertions
143+
include TestProcess, RequestHelpers, Assertions
144144

145145
%w( status status_message headers body redirect? ).each do |method|
146146
delegate method, :to => :response, :allow_nil => true
@@ -684,7 +684,7 @@ def method_missing(sym, *args, &block)
684684
# Consult the Rails Testing Guide for more.
685685

686686
class IntegrationTest < ActiveSupport::TestCase
687-
include TestProcess
687+
include TestProcess::FixtureFile
688688

689689
module UrlOptions
690690
extend ActiveSupport::Concern

actionpack/lib/action_dispatch/testing/test_process.rb

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,26 @@
33

44
module ActionDispatch
55
module TestProcess
6+
module FixtureFile
7+
# Shortcut for <tt>Rack::Test::UploadedFile.new(File.join(ActionDispatch::IntegrationTest.fixture_path, path), type)</tt>:
8+
#
9+
# post :change_avatar, avatar: fixture_file_upload('files/spongebob.png', 'image/png')
10+
#
11+
# To upload binary files on Windows, pass <tt>:binary</tt> as the last parameter.
12+
# This will not affect other platforms:
13+
#
14+
# post :change_avatar, avatar: fixture_file_upload('files/spongebob.png', 'image/png', :binary)
15+
def fixture_file_upload(path, mime_type = nil, binary = false)
16+
if self.class.respond_to?(:fixture_path) && self.class.fixture_path &&
17+
!File.exist?(path)
18+
path = File.join(self.class.fixture_path, path)
19+
end
20+
Rack::Test::UploadedFile.new(path, mime_type, binary)
21+
end
22+
end
23+
24+
include FixtureFile
25+
626
def assigns(key = nil)
727
raise NoMethodError,
828
"assigns has been extracted to a gem. To continue using it,
@@ -24,21 +44,5 @@ def cookies
2444
def redirect_to_url
2545
@response.redirect_url
2646
end
27-
28-
# Shortcut for <tt>Rack::Test::UploadedFile.new(File.join(ActionDispatch::IntegrationTest.fixture_path, path), type)</tt>:
29-
#
30-
# post :change_avatar, avatar: fixture_file_upload('files/spongebob.png', 'image/png')
31-
#
32-
# To upload binary files on Windows, pass <tt>:binary</tt> as the last parameter.
33-
# This will not affect other platforms:
34-
#
35-
# post :change_avatar, avatar: fixture_file_upload('files/spongebob.png', 'image/png', :binary)
36-
def fixture_file_upload(path, mime_type = nil, binary = false)
37-
if self.class.respond_to?(:fixture_path) && self.class.fixture_path &&
38-
!File.exist?(path)
39-
path = File.join(self.class.fixture_path, path)
40-
end
41-
Rack::Test::UploadedFile.new(path, mime_type, binary)
42-
end
4347
end
4448
end

0 commit comments

Comments
 (0)