|
4 | 4 |
|
5 | 5 | describe MergeRequestDiffFile do
|
6 | 6 | describe '#diff' do
|
7 |
| - let(:unpacked) { 'unpacked' } |
8 |
| - let(:packed) { [unpacked].pack('m0') } |
| 7 | + context 'when diff is not stored' do |
| 8 | + let(:unpacked) { 'unpacked' } |
| 9 | + let(:packed) { [unpacked].pack('m0') } |
9 | 10 |
|
10 |
| - before do |
11 |
| - subject.diff = packed |
12 |
| - end |
13 |
| - |
14 |
| - context 'when the diff is marked as binary' do |
15 | 11 | before do
|
16 |
| - subject.binary = true |
| 12 | + subject.diff = packed |
| 13 | + end |
| 14 | + |
| 15 | + context 'when the diff is marked as binary' do |
| 16 | + before do |
| 17 | + subject.binary = true |
| 18 | + end |
| 19 | + |
| 20 | + it 'unpacks from base 64' do |
| 21 | + expect(subject.diff).to eq(unpacked) |
| 22 | + end |
| 23 | + end |
| 24 | + |
| 25 | + context 'when the diff is not marked as binary' do |
| 26 | + it 'returns the raw diff' do |
| 27 | + expect(subject.diff).to eq(packed) |
| 28 | + end |
17 | 29 | end
|
| 30 | + end |
18 | 31 |
|
19 |
| - it 'unpacks from base 64' do |
20 |
| - expect(subject.diff).to eq(unpacked) |
| 32 | + context 'when diff is stored in DB' do |
| 33 | + let(:file) { create(:merge_request).merge_request_diff.merge_request_diff_files.first } |
| 34 | + |
| 35 | + it 'returns UTF-8 string' do |
| 36 | + expect(file.diff.encoding).to eq Encoding::UTF_8 |
21 | 37 | end
|
22 | 38 | end
|
23 | 39 |
|
24 |
| - context 'when the diff is not marked as binary' do |
25 |
| - it 'returns the raw diff' do |
26 |
| - expect(subject.diff).to eq(packed) |
| 40 | + context 'when diff is stored in external storage' do |
| 41 | + let(:file) { create(:merge_request).merge_request_diff.merge_request_diff_files.first } |
| 42 | + let(:test_dir) { 'tmp/tests/external-diffs' } |
| 43 | + |
| 44 | + around do |example| |
| 45 | + FileUtils.mkdir_p(test_dir) |
| 46 | + |
| 47 | + begin |
| 48 | + example.run |
| 49 | + ensure |
| 50 | + FileUtils.rm_rf(test_dir) |
| 51 | + end |
| 52 | + end |
| 53 | + |
| 54 | + before do |
| 55 | + stub_external_diffs_setting(enabled: true, storage_path: test_dir) |
| 56 | + end |
| 57 | + |
| 58 | + it 'returns UTF-8 string' do |
| 59 | + expect(file.diff.encoding).to eq Encoding::UTF_8 |
27 | 60 | end
|
28 | 61 | end
|
29 | 62 | end
|
|
0 commit comments