2012-11-24 18:04:13 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2013-06-23 13:25:06 -04:00
|
|
|
describe Projects::MergeRequestsController do
|
2014-01-22 14:03:52 -05:00
|
|
|
let(:project) { create(:project) }
|
2012-11-24 18:04:13 -05:00
|
|
|
let(:user) { create(:user) }
|
2014-01-14 03:47:28 -05:00
|
|
|
let(:merge_request) { create(:merge_request_with_diffs, target_project: project, source_project: project, target_branch: "stable", source_branch: "master") }
|
2012-11-24 18:04:13 -05:00
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
2013-01-04 11:50:31 -05:00
|
|
|
project.team << [user, :master]
|
2013-08-20 09:56:05 -04:00
|
|
|
Projects::MergeRequestsController.any_instance.stub(validates_merge_request: true, )
|
2012-11-24 18:04:13 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "#show" do
|
2013-04-07 16:58:25 -04:00
|
|
|
shared_examples "export merge as" do |format|
|
2012-11-24 18:04:13 -05:00
|
|
|
it "should generally work" do
|
2013-09-05 07:46:34 -04:00
|
|
|
get :show, project_id: project.to_param, id: merge_request.iid, format: format
|
2012-11-24 18:04:13 -05:00
|
|
|
|
|
|
|
expect(response).to be_success
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should generate it" do
|
|
|
|
MergeRequest.any_instance.should_receive(:"to_#{format}")
|
|
|
|
|
2013-09-05 07:46:34 -04:00
|
|
|
get :show, project_id: project.to_param, id: merge_request.iid, format: format
|
2012-11-24 18:04:13 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should render it" do
|
2013-09-05 07:46:34 -04:00
|
|
|
get :show, project_id: project.to_param, id: merge_request.iid, format: format
|
2012-11-24 18:04:13 -05:00
|
|
|
|
2013-04-25 10:15:33 -04:00
|
|
|
expect(response.body).to eq((merge_request.send(:"to_#{format}",user)).to_s)
|
2012-11-24 18:04:13 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should not escape Html" do
|
|
|
|
MergeRequest.any_instance.stub(:"to_#{format}").and_return('HTML entities &<>" ')
|
|
|
|
|
2013-09-05 07:46:34 -04:00
|
|
|
get :show, project_id: project.to_param, id: merge_request.iid, format: format
|
2012-11-24 18:04:13 -05:00
|
|
|
|
|
|
|
expect(response.body).to_not include('&')
|
|
|
|
expect(response.body).to_not include('>')
|
|
|
|
expect(response.body).to_not include('<')
|
|
|
|
expect(response.body).to_not include('"')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "as diff" do
|
2013-04-07 16:58:25 -04:00
|
|
|
include_examples "export merge as", :diff
|
2012-11-24 18:04:13 -05:00
|
|
|
let(:format) { :diff }
|
|
|
|
|
|
|
|
it "should really only be a git diff" do
|
2013-09-05 07:46:34 -04:00
|
|
|
get :show, project_id: project.to_param, id: merge_request.iid, format: format
|
2012-11-24 18:04:13 -05:00
|
|
|
|
|
|
|
expect(response.body).to start_with("diff --git")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "as patch" do
|
2013-04-07 16:58:25 -04:00
|
|
|
include_examples "export merge as", :patch
|
2012-11-24 18:04:13 -05:00
|
|
|
let(:format) { :patch }
|
|
|
|
|
|
|
|
it "should really be a git email patch with commit" do
|
2013-09-05 07:46:34 -04:00
|
|
|
get :show, project_id: project.to_param, id: merge_request.iid, format: format
|
2012-11-24 18:04:13 -05:00
|
|
|
|
2014-01-14 03:47:28 -05:00
|
|
|
expect(response.body[0..100]).to start_with("From 6ea87c47f0f8a24ae031c3fff17bc913889ecd00")
|
2012-11-24 18:04:13 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should contain git diffs" do
|
2013-09-05 07:46:34 -04:00
|
|
|
get :show, project_id: project.to_param, id: merge_request.iid, format: format
|
2012-11-24 18:04:13 -05:00
|
|
|
|
|
|
|
expect(response.body).to match(/^diff --git/)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|