提交 96a1a2a3 编写于 作者: E Eugene Kenny

Use binread instead of setting file mode manually

Followup to b3102205.
上级 f43e4a78
......@@ -4,7 +4,7 @@
module TestApiFileUtils
def file_path() __FILE__ end
def file_data() @data ||= File.open(file_path, "rb") { |f| f.read } end
def file_data() @data ||= File.binread(file_path) end
end
class DataStreamingApiController < ActionController::API
......
......@@ -5,7 +5,7 @@
module TestFileUtils
def file_name() File.basename(__FILE__) end
def file_path() __FILE__ end
def file_data() @data ||= File.open(file_path, "rb") { |f| f.read } end
def file_data() @data ||= File.binread(file_path) end
end
class SendFileController < ActionController::Base
......
......@@ -10,7 +10,7 @@ def get_binding
end
def binary(path)
%(!!binary "#{Base64.strict_encode64(File.read(path, mode: 'rb'))}")
%(!!binary "#{Base64.strict_encode64(File.binread(path))}")
end
end
end
......
......@@ -529,7 +529,7 @@ def test_subsubdir_file_with_arbitrary_name
end
def test_binary_in_fixtures
data = File.open(ASSETS_ROOT + "/flowers.jpg", "rb") { |f| f.read }
data = File.binread(ASSETS_ROOT + "/flowers.jpg")
data.force_encoding("ASCII-8BIT")
data.freeze
assert_equal data, @flowers.data
......
......@@ -611,7 +611,7 @@ class Notifier < ActionMailer::Base
default from: "from@example.com"
def foo
attachments['pixel.png'] = File.read("#{app_path}/public/images/pixel.png", mode: 'rb')
attachments['pixel.png'] = File.binread("#{app_path}/public/images/pixel.png")
mail to: "to@example.org"
end
end
......@@ -648,7 +648,7 @@ class Notifier < ActionMailer::Base
default from: "from@example.com"
def foo
attachments['pixel.png'] = File.read("#{app_path}/public/images/pixel.png", mode: 'rb')
attachments['pixel.png'] = File.binread("#{app_path}/public/images/pixel.png")
mail to: "to@example.org"
end
end
......@@ -693,7 +693,7 @@ class Notifier < ActionMailer::Base
default from: "from@example.com"
def foo
attachments['pixel.png'] = File.read("#{app_path}/public/images/pixel.png", mode: 'rb')
attachments['pixel.png'] = File.binread("#{app_path}/public/images/pixel.png")
mail to: "to@example.org"
end
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册