Commit d34481d1 authored by Stan Hu's avatar Stan Hu

Use encoding constants instead of strings

This eliminates an extra lookup.
parent f0d3c690
......@@ -82,9 +82,9 @@ module Ci
def append_strings(old_data, new_data)
if Feature.enabled?(:ci_job_trace_force_encode, default_enabled: :yaml)
# When object storage is in use, old_data may be retrieved in UTF-8.
old_data = old_data.force_encoding('ASCII-8BIT')
old_data = old_data.force_encoding(Encoding::ASCII_8BIT)
# new_data should already be in ASCII-8BIT, but just in case it isn't, do this.
new_data = new_data.force_encoding('ASCII-8BIT')
new_data = new_data.force_encoding(Encoding::ASCII_8BIT)
end
old_data + new_data
......
......@@ -103,7 +103,7 @@ RSpec.describe Ci::BuildTraceChunks::Fog do
end
describe '#append_data' do
let(:initial_data) { (+'😺').force_encoding('ASCII-8BIT') }
let(:initial_data) { (+'😺').force_encoding(Encoding::ASCII_8BIT) }
let(:model) { create(:ci_build_trace_chunk, :fog_with_data, initial_data: initial_data) }
let(:data) { data_store.data(model) }
......@@ -111,15 +111,15 @@ RSpec.describe Ci::BuildTraceChunks::Fog do
it 'appends ASCII data' do
data_store.append_data(model, +'hello world', 4)
expect(data.encoding).to eq(Encoding.find('ASCII-8BIT'))
expect(data.force_encoding('UTF-8')).to eq('😺hello world')
expect(data.encoding).to eq(Encoding::ASCII_8BIT)
expect(data.force_encoding(Encoding::UTF_8)).to eq('😺hello world')
end
it 'appends UTF-8 data' do
data_store.append_data(model, +'Résumé', 4)
expect(data.encoding).to eq(Encoding.find('ASCII-8BIT'))
expect(data.force_encoding('UTF-8')).to eq("😺Résumé")
expect(data.encoding).to eq(Encoding::ASCII_8BIT)
expect(data.force_encoding(Encoding::UTF_8)).to eq("😺Résumé")
end
context 'when initial data is UTF-8' do
......@@ -128,8 +128,8 @@ RSpec.describe Ci::BuildTraceChunks::Fog do
it 'appends ASCII data' do
data_store.append_data(model, +'hello world', 4)
expect(data.encoding).to eq(Encoding.find('ASCII-8BIT'))
expect(data.force_encoding('UTF-8')).to eq('😺hello world')
expect(data.encoding).to eq(Encoding::ASCII_8BIT)
expect(data.force_encoding(Encoding::UTF_8)).to eq('😺hello world')
end
end
end
......@@ -142,8 +142,8 @@ RSpec.describe Ci::BuildTraceChunks::Fog do
it 'appends ASCII data' do
data_store.append_data(model, +'hello world', 4)
expect(data.encoding).to eq(Encoding.find('ASCII-8BIT'))
expect(data.force_encoding('UTF-8')).to eq('😺hello world')
expect(data.encoding).to eq(Encoding::ASCII_8BIT)
expect(data.force_encoding(Encoding::UTF_8)).to eq('😺hello world')
end
it 'throws an exception when appending UTF-8 data' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment