2017-07-09 13:41:28 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2011-06-06 14:17:44 -04:00
|
|
|
require "cases/helper"
|
2020-04-11 13:44:27 -04:00
|
|
|
require "models/binary"
|
2005-01-01 13:34:39 -05:00
|
|
|
|
2020-04-11 13:44:27 -04:00
|
|
|
class BinaryTest < ActiveRecord::TestCase
|
|
|
|
FIXTURES = %w(flowers.jpg example.log test.txt)
|
2005-09-26 16:29:06 -04:00
|
|
|
|
2020-04-11 13:44:27 -04:00
|
|
|
def test_mixed_encoding
|
|
|
|
str = +"\x80"
|
|
|
|
str.force_encoding("ASCII-8BIT")
|
2005-07-01 13:20:04 -04:00
|
|
|
|
2020-04-11 13:44:27 -04:00
|
|
|
binary = Binary.new name: "いただきます!", data: str
|
|
|
|
binary.save!
|
|
|
|
binary.reload
|
|
|
|
assert_equal str, binary.data
|
2011-04-13 18:35:53 -04:00
|
|
|
|
2020-04-11 13:44:27 -04:00
|
|
|
name = binary.name
|
2011-04-13 18:35:53 -04:00
|
|
|
|
2020-04-11 13:44:27 -04:00
|
|
|
assert_equal "いただきます!", name
|
|
|
|
end
|
2011-04-13 18:35:53 -04:00
|
|
|
|
2020-04-11 13:44:27 -04:00
|
|
|
def test_load_save
|
|
|
|
Binary.delete_all
|
2007-11-21 20:29:19 -05:00
|
|
|
|
2020-04-11 13:44:27 -04:00
|
|
|
FIXTURES.each do |filename|
|
|
|
|
data = File.read(ASSETS_ROOT + "/#{filename}")
|
|
|
|
data.force_encoding("ASCII-8BIT")
|
|
|
|
data.freeze
|
2007-11-21 20:29:19 -05:00
|
|
|
|
2020-04-11 13:44:27 -04:00
|
|
|
bin = Binary.new(data: data)
|
|
|
|
assert_equal data, bin.data, "Newly assigned data differs from original"
|
2005-01-01 13:34:39 -05:00
|
|
|
|
2020-04-11 13:44:27 -04:00
|
|
|
bin.save!
|
|
|
|
assert_equal data, bin.data, "Data differs from original after save"
|
2005-01-01 13:34:39 -05:00
|
|
|
|
2020-04-11 13:44:27 -04:00
|
|
|
assert_equal data, bin.reload.data, "Reloaded data differs from original"
|
2005-09-26 16:29:06 -04:00
|
|
|
end
|
2005-01-01 13:34:39 -05:00
|
|
|
end
|
2005-01-03 18:00:44 -05:00
|
|
|
end
|