summaryrefslogtreecommitdiff
path: root/spec/controllers/projects/compare_controller_spec.rb
blob: 788a609ee40230f53ced6c455fc136a761f54ec9 (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
67
require 'spec_helper'

describe Projects::CompareController do
  let(:project) { create(:project) }
  let(:user) { create(:user) }
  let(:ref_from) { "improve%2Fawesome" }
  let(:ref_to) { "feature" }

  before do
    sign_in(user)
    project.team << [user, :master]
  end

  it 'compare should show some diffs' do
    get(:show,
        namespace_id: project.namespace.to_param,
        project_id: project.to_param,
        from: ref_from,
        to: ref_to)

    expect(response).to be_success
    expect(assigns(:diffs).first).to_not be_nil
    expect(assigns(:commits).length).to be >= 1
  end

  it 'compare should show some diffs with ignore whitespace change option' do
    get(:show,
        namespace_id: project.namespace.to_param,
        project_id: project.to_param,
        from: '08f22f25',
        to: '66eceea0',
        w: 1)

    expect(response).to be_success
    expect(assigns(:diffs).first).to_not be_nil
    expect(assigns(:commits).length).to be >= 1
    # without whitespace option, there are more than 2 diff_splits
    diff_splits = assigns(:diffs).first.diff.split("\n")
    expect(diff_splits.length).to be <= 2
  end

  describe 'non-existent refs' do
    it 'invalid source ref' do
      get(:show,
          namespace_id: project.namespace.to_param,
          project_id: project.to_param,
          from: 'non-existent',
          to: ref_to)

      expect(response).to be_success
      expect(assigns(:diffs).to_a).to eq([])
      expect(assigns(:commits)).to eq([])
    end

    it 'invalid target ref' do
      get(:show,
          namespace_id: project.namespace.to_param,
          project_id: project.to_param,
          from: ref_from,
          to: 'non-existent')

      expect(response).to be_success
      expect(assigns(:diffs)).to eq(nil)
      expect(assigns(:commits)).to eq(nil)
    end
  end
end