summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/git/raw_diff_change_spec.rb
blob: a0bb37fd84a27794c64fef5ec0d815a51a699461 (plain)
1
2
3
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
require 'spec_helper'

describe Gitlab::Git::RawDiffChange do
  let(:raw_change) { }
  let(:change) { described_class.new(raw_change) }

  context 'bad input' do
    let(:raw_change) { 'foo' }

    it 'does not set most of the attrs' do
      expect(change.blob_id).to eq('foo')
      expect(change.operation).to eq(:unknown)
      expect(change.old_path).to be_blank
      expect(change.new_path).to be_blank
      expect(change.blob_size).to eq(0)
    end
  end

  context 'adding a file' do
    let(:raw_change) { '93e123ac8a3e6a0b600953d7598af629dec7b735 59 A  bar/branch-test.txt' }

    it 'initialize the proper attrs' do
      expect(change.operation).to eq(:added)
      expect(change.old_path).to be_blank
      expect(change.new_path).to eq('bar/branch-test.txt')
      expect(change.blob_id).to be_present
      expect(change.blob_size).to be_present
    end
  end

  context 'renaming a file' do
    let(:raw_change) { "85bc2f9753afd5f4fc5d7c75f74f8d526f26b4f3 107 R060\tfiles/js/commit.js.coffee\tfiles/js/commit.coffee" }

    it 'initialize the proper attrs' do
      expect(change.operation).to eq(:renamed)
      expect(change.old_path).to eq('files/js/commit.js.coffee')
      expect(change.new_path).to eq('files/js/commit.coffee')
      expect(change.blob_id).to be_present
      expect(change.blob_size).to be_present
    end
  end

  context 'modifying a file' do
    let(:raw_change) { 'c60514b6d3d6bf4bec1030f70026e34dfbd69ad5 824 M  README.md' }

    it 'initialize the proper attrs' do
      expect(change.operation).to eq(:modified)
      expect(change.old_path).to eq('README.md')
      expect(change.new_path).to eq('README.md')
      expect(change.blob_id).to be_present
      expect(change.blob_size).to be_present
    end
  end

  context 'deleting a file' do
    let(:raw_change) { '60d7a906c2fd9e4509aeb1187b98d0ea7ce827c9 15364 D  files/.DS_Store' }

    it 'initialize the proper attrs' do
      expect(change.operation).to eq(:deleted)
      expect(change.old_path).to eq('files/.DS_Store')
      expect(change.new_path).to be_nil
      expect(change.blob_id).to be_present
      expect(change.blob_size).to be_present
    end
  end
end