2019-07-25 01:21:37 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-06-29 09:37:37 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe Gitlab::Database::ShaAttribute do
|
2017-06-29 09:37:37 -04:00
|
|
|
let(:sha) do
|
|
|
|
'9a573a369a5bfbb9a4a36e98852c21af8a44ea8b'
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:binary_sha) do
|
|
|
|
[sha].pack('H*')
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:binary_from_db) do
|
2019-07-24 09:59:55 -04:00
|
|
|
"\\x#{sha}"
|
2017-06-29 09:37:37 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
let(:attribute) { described_class.new }
|
|
|
|
|
2018-04-06 06:57:19 -04:00
|
|
|
describe '#deserialize' do
|
2017-06-29 09:37:37 -04:00
|
|
|
it 'converts the binary SHA to a String' do
|
2018-04-06 06:57:19 -04:00
|
|
|
expect(attribute.deserialize(binary_from_db)).to eq(sha)
|
2017-06-29 09:37:37 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-04-06 06:57:19 -04:00
|
|
|
describe '#serialize' do
|
2017-06-29 09:37:37 -04:00
|
|
|
it 'converts a SHA String to binary data' do
|
2020-01-29 10:08:59 -05:00
|
|
|
expect(described_class.serialize(sha).to_s).to eq(binary_sha)
|
2017-06-29 09:37:37 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|