BigW Consortium Gitlab

merge_requests_controller_spec.rb 2.41 KB
Newer Older
1 2
require 'spec_helper'

3
describe Projects::MergeRequestsController do
4
  let(:project) { create(:project) }
5
  let(:user)    { create(:user) }
6
  let(:merge_request) { create(:merge_request_with_diffs, target_project: project, source_project: project, target_branch: "stable", source_branch: "master") }
7 8 9

  before do
    sign_in(user)
Dmitriy Zaporozhets committed
10
    project.team << [user, :master]
11
    Projects::MergeRequestsController.any_instance.stub(validates_merge_request: true, )
12 13 14
  end

  describe "#show" do
15
    shared_examples "export merge as" do |format|
16
      it "should generally work" do
17
        get :show, project_id: project.to_param, id: merge_request.iid, format: format
18 19 20 21 22 23 24

        expect(response).to be_success
      end

      it "should generate it" do
        MergeRequest.any_instance.should_receive(:"to_#{format}")

25
        get :show, project_id: project.to_param, id: merge_request.iid, format: format
26 27 28
      end

      it "should render it" do
29
        get :show, project_id: project.to_param, id: merge_request.iid, format: format
30

31
        expect(response.body).to eq((merge_request.send(:"to_#{format}",user)).to_s)
32 33 34 35 36
      end

      it "should not escape Html" do
        MergeRequest.any_instance.stub(:"to_#{format}").and_return('HTML entities &<>" ')

37
        get :show, project_id: project.to_param, id: merge_request.iid, format: format
38 39 40 41 42 43 44 45 46

        expect(response.body).to_not include('&amp;')
        expect(response.body).to_not include('&gt;')
        expect(response.body).to_not include('&lt;')
        expect(response.body).to_not include('&quot;')
      end
    end

    describe "as diff" do
47
      include_examples "export merge as", :diff
48 49 50
      let(:format) { :diff }

      it "should really only be a git diff" do
51
        get :show, project_id: project.to_param, id: merge_request.iid, format: format
52 53 54 55 56 57

        expect(response.body).to start_with("diff --git")
      end
    end

    describe "as patch" do
58
      include_examples "export merge as", :patch
59 60 61
      let(:format) { :patch }

      it "should really be a git email patch with commit" do
62
        get :show, project_id: project.to_param, id: merge_request.iid, format: format
63

64
        expect(response.body[0..100]).to start_with("From 6ea87c47f0f8a24ae031c3fff17bc913889ecd00")
65 66 67
      end

      it "should contain git diffs" do
68
        get :show, project_id: project.to_param, id: merge_request.iid, format: format
69 70 71 72 73 74

        expect(response.body).to match(/^diff --git/)
      end
    end
  end
end