33
44module 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
4448end
0 commit comments