merge_request_diff_file_spec.rb 782 Bytes
Newer Older
1 2
require 'rails_helper'

3
describe MergeRequestDiffFile do
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
  describe '#diff' do
    let(:unpacked) { 'unpacked' }
    let(:packed) { [unpacked].pack('m0') }

    before do
      subject.diff = packed
    end

    context 'when the diff is marked as binary' do
      before do
        subject.binary = true
      end

      it 'unpacks from base 64' do
        expect(subject.diff).to eq(unpacked)
      end
    end

    context 'when the diff is not marked as binary' do
      it 'returns the raw diff' do
        expect(subject.diff).to eq(packed)
      end
    end
  end

29
  describe '#utf8_diff' do
30
    it 'does not raise error when the diff is binary' do
31 32 33 34 35 36
      subject.diff = "\x05\x00\x68\x65\x6c\x6c\x6f"

      expect { subject.utf8_diff }.not_to raise_error
    end
  end
end