Use binread instead of setting file mode manually

Followup to b31022052a.
This commit is contained in:
Eugene Kenny 2020-05-13 00:05:32 +01:00
parent f43e4a78bd
commit 96a1a2a37c
5 changed files with 7 additions and 7 deletions

View File

@ -4,7 +4,7 @@ require "abstract_unit"
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

View File

@ -5,7 +5,7 @@ require "abstract_unit"
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

View File

@ -10,7 +10,7 @@ class ActiveRecord::FixtureSet::RenderContext # :nodoc:
end
def binary(path)
%(!!binary "#{Base64.strict_encode64(File.read(path, mode: 'rb'))}")
%(!!binary "#{Base64.strict_encode64(File.binread(path))}")
end
end
end

View File

@ -529,7 +529,7 @@ class FixturesTest < ActiveRecord::TestCase
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

View File

@ -611,7 +611,7 @@ module ApplicationTests
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 @@ module ApplicationTests
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 @@ module ApplicationTests
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