-
Notifications
You must be signed in to change notification settings - Fork 259
/
Copy pathmock_file.rb
33 lines (28 loc) · 953 Bytes
/
mock_file.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
module Cms
# Simplified handling for creating files for writing tests around multipart uploads.
module MockFile
FILES_DIR = File.dirname(__FILE__) + '/fixtures/multipart'
# Creates a file to test uploading to a sample file.
def self.new_file(file_name='foo.jpg', content_type="image/jpeg")
Rack::Test::UploadedFile.new("#{FILES_DIR}/#{file_name}", content_type, false)
end
end
# For activating logging on the console
def self.activate_logging
ActiveRecord::Base.logger = Logger.new(STDOUT)
end
end
module Extensions
module Rack
module Test
# Extensions to make Rack::Test::UploadedFile function like ActionDispatch::Http::UploadedFile during unit/functional tests.
module UploadedFile
# Attachment relies on this being there
def tempfile
@tempfile
end
end
end
end
end
Rack::Test::UploadedFile.send(:include, Extensions::Rack::Test::UploadedFile)