summaryrefslogtreecommitdiff
path: root/spec/requests
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-07-30 13:35:33 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-07-30 13:35:33 +0300
commit0d715bcd812ca6c99884e117f28a400669aa8e57 (patch)
tree5690fa43c790af40c51441425b9d8be068d4139d /spec/requests
parent4f07a6a99cab8f8ae3ad0a786a6cc9a837955c08 (diff)
parent4d373005968b8269a8d2fe56b7776820396127a4 (diff)
downloadgitlab-ce-0d715bcd812ca6c99884e117f28a400669aa8e57.tar.gz
Merge branch 'mr-on-fork' of https://github.com/karlhungus/gitlabhq into karlhungus-mr-on-fork
Conflicts: app/views/projects/commit/show.html.haml app/views/projects/compare/show.html.haml app/views/projects/merge_requests/branch_from.js.haml
Diffstat (limited to 'spec/requests')
-rw-r--r--spec/requests/api/merge_requests_spec.rb133
-rw-r--r--spec/requests/api/milestones_spec.rb1
-rw-r--r--spec/requests/api/notes_spec.rb2
-rw-r--r--spec/requests/api/projects_spec.rb2
-rw-r--r--spec/requests/api/repositories_spec.rb1
5 files changed, 106 insertions, 33 deletions
diff --git a/spec/requests/api/merge_requests_spec.rb b/spec/requests/api/merge_requests_spec.rb
index 5bf228a7448..7b893c43379 100644
--- a/spec/requests/api/merge_requests_spec.rb
+++ b/spec/requests/api/merge_requests_spec.rb
@@ -3,10 +3,12 @@ require "spec_helper"
describe API::API do
include ApiHelpers
- let(:user) { create(:user ) }
- let!(:project) { create(:project_with_code, creator_id: user.id) }
- let!(:merge_request) { create(:merge_request, author: user, assignee: user, project: project, title: "Test") }
- before { project.team << [user, :reporters] }
+ let(:user) { create(:user) }
+ let!(:project) {create(:project_with_code, creator_id: user.id) }
+ let!(:merge_request) { create(:merge_request, author: user, assignee: user, source_project: project, target_project: project, title: "Test") }
+ before {
+ project.team << [user, :reporters]
+ }
describe "GET /projects/:id/merge_requests" do
context "when unauthenticated" do
@@ -40,35 +42,104 @@ describe API::API do
end
describe "POST /projects/:id/merge_requests" do
- it "should return merge_request" do
- post api("/projects/#{project.id}/merge_requests", user),
- title: 'Test merge_request', source_branch: "stable", target_branch: "master", author: user
- response.status.should == 201
- json_response['title'].should == 'Test merge_request'
- end
+ context 'between branches projects' do
+ it "should return merge_request" do
+ post api("/projects/#{project.id}/merge_requests", user),
+ title: 'Test merge_request', source_branch: "stable", target_branch: "master", author: user
+ response.status.should == 201
+ json_response['title'].should == 'Test merge_request'
+ end
- it "should return 422 when source_branch equals target_branch" do
- post api("/projects/#{project.id}/merge_requests", user),
- title: "Test merge_request", source_branch: "master", target_branch: "master", author: user
- response.status.should == 422
- end
+ it "should return 422 when source_branch equals target_branch" do
+ post api("/projects/#{project.id}/merge_requests", user),
+ title: "Test merge_request", source_branch: "master", target_branch: "master", author: user
+ response.status.should == 422
+ end
- it "should return 400 when source_branch is missing" do
- post api("/projects/#{project.id}/merge_requests", user),
- title: "Test merge_request", target_branch: "master", author: user
- response.status.should == 400
- end
+ it "should return 400 when source_branch is missing" do
+ post api("/projects/#{project.id}/merge_requests", user),
+ title: "Test merge_request", target_branch: "master", author: user
+ response.status.should == 400
+ end
- it "should return 400 when target_branch is missing" do
- post api("/projects/#{project.id}/merge_requests", user),
- title: "Test merge_request", source_branch: "stable", author: user
- response.status.should == 400
+ it "should return 400 when target_branch is missing" do
+ post api("/projects/#{project.id}/merge_requests", user),
+ title: "Test merge_request", source_branch: "stable", author: user
+ response.status.should == 400
+ end
+
+ it "should return 400 when title is missing" do
+ post api("/projects/#{project.id}/merge_requests", user),
+ target_branch: 'master', source_branch: 'stable'
+ response.status.should == 400
+ end
end
- it "should return 400 when title is missing" do
- post api("/projects/#{project.id}/merge_requests", user),
- target_branch: 'master', source_branch: 'stable'
- response.status.should == 400
+ context 'forked projects' do
+ let!(:user2) {create(:user)}
+ let!(:forked_project_link) { build(:forked_project_link) }
+ let!(:fork_project) { create(:source_project_with_code, forked_project_link: forked_project_link, namespace: user2.namespace, creator_id: user2.id) }
+ let!(:unrelated_project) { create(:target_project_with_code, namespace: user2.namespace, creator_id: user2.id) }
+
+ before :each do |each|
+ fork_project.team << [user2, :reporters]
+ forked_project_link.forked_from_project = project
+ forked_project_link.forked_to_project = fork_project
+ forked_project_link.save!
+ end
+
+ it "should return merge_request" do
+ post api("/projects/#{fork_project.id}/merge_requests", user2),
+ title: 'Test merge_request', source_branch: "stable", target_branch: "master", author: user2, target_project_id: project.id
+ response.status.should == 201
+ json_response['title'].should == 'Test merge_request'
+ end
+
+ it "should not return 422 when source_branch equals target_branch" do
+ project.id.should_not == fork_project.id
+ fork_project.forked?.should be_true
+ fork_project.forked_from_project.should == project
+ post api("/projects/#{fork_project.id}/merge_requests", user2),
+ title: 'Test merge_request', source_branch: "master", target_branch: "master", author: user2, target_project_id: project.id
+ response.status.should == 201
+ json_response['title'].should == 'Test merge_request'
+ end
+
+ it "should return 400 when source_branch is missing" do
+ post api("/projects/#{fork_project.id}/merge_requests", user2),
+ title: 'Test merge_request', target_branch: "master", author: user2, target_project_id: project.id
+ response.status.should == 400
+ end
+
+ it "should return 400 when target_branch is missing" do
+ post api("/projects/#{fork_project.id}/merge_requests", user2),
+ title: 'Test merge_request', target_branch: "master", author: user2, target_project_id: project.id
+ response.status.should == 400
+ end
+
+ it "should return 400 when title is missing" do
+ post api("/projects/#{fork_project.id}/merge_requests", user2),
+ target_branch: 'master', source_branch: 'stable', author: user2, target_project_id: project.id
+ response.status.should == 400
+ end
+
+ it "should return 400 when target_branch is specified and not a forked project" do
+ post api("/projects/#{project.id}/merge_requests", user),
+ title: 'Test merge_request', target_branch: 'master', source_branch: 'stable', author: user, target_project_id: fork_project.id
+ response.status.should == 400
+ end
+
+ it "should return 400 when target_branch is specified and for a different fork" do
+ post api("/projects/#{fork_project.id}/merge_requests", user2),
+ title: 'Test merge_request', target_branch: 'master', source_branch: 'stable', author: user2, target_project_id: unrelated_project.id
+ response.status.should == 400
+ end
+
+ it "should return 201 when target_branch is specified and for the same project" do
+ post api("/projects/#{fork_project.id}/merge_requests", user2),
+ title: 'Test merge_request', target_branch: 'master', source_branch: 'stable', author: user2, target_project_id: fork_project.id
+ response.status.should == 201
+ end
end
end
@@ -97,14 +168,14 @@ describe API::API do
it "should return 422 when source_branch and target_branch are renamed the same" do
put api("/projects/#{project.id}/merge_request/#{merge_request.id}", user),
- source_branch: "master", target_branch: "master"
+ source_branch: "master", target_branch: "master"
response.status.should == 422
end
it "should return merge_request with renamed target_branch" do
- put api("/projects/#{project.id}/merge_request/#{merge_request.id}", user), target_branch: "test"
+ put api("/projects/#{project.id}/merge_request/#{merge_request.id}", user), target_branch: "wiki"
response.status.should == 200
- json_response['target_branch'].should == 'test'
+ json_response['target_branch'].should == 'wiki'
end
end
diff --git a/spec/requests/api/milestones_spec.rb b/spec/requests/api/milestones_spec.rb
index af12c088c8f..246fe262ce8 100644
--- a/spec/requests/api/milestones_spec.rb
+++ b/spec/requests/api/milestones_spec.rb
@@ -3,6 +3,7 @@ require 'spec_helper'
describe API::API do
include ApiHelpers
before(:each) { enable_observers }
+ after(:each) {disable_observers}
let(:user) { create(:user) }
let!(:project) { create(:project, namespace: user.namespace ) }
diff --git a/spec/requests/api/notes_spec.rb b/spec/requests/api/notes_spec.rb
index 11296aea73e..48a2d111f8c 100644
--- a/spec/requests/api/notes_spec.rb
+++ b/spec/requests/api/notes_spec.rb
@@ -6,7 +6,7 @@ describe API::API do
let(:user) { create(:user) }
let!(:project) { create(:project, namespace: user.namespace ) }
let!(:issue) { create(:issue, project: project, author: user) }
- let!(:merge_request) { create(:merge_request, project: project, author: user) }
+ let!(:merge_request) { create(:merge_request, source_project: project, target_project: project, author: user) }
let!(:snippet) { create(:project_snippet, project: project, author: user) }
let!(:issue_note) { create(:note, noteable: issue, project: project, author: user) }
let!(:merge_request_note) { create(:note, noteable: merge_request, project: project, author: user) }
diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb
index 863ecc61bbb..2de3dc55e40 100644
--- a/spec/requests/api/projects_spec.rb
+++ b/spec/requests/api/projects_spec.rb
@@ -3,6 +3,7 @@ require 'spec_helper'
describe API::API do
include ApiHelpers
before(:each) { enable_observers }
+ after(:each) { disable_observers }
let(:user) { create(:user) }
let(:user2) { create(:user) }
@@ -475,7 +476,6 @@ describe API::API do
end
end
-
describe "GET /projects/:id/snippets" do
it "should return an array of project snippets" do
get api("/projects/#{project.id}/snippets", user)
diff --git a/spec/requests/api/repositories_spec.rb b/spec/requests/api/repositories_spec.rb
index 13e6627840e..afa67d1ecbe 100644
--- a/spec/requests/api/repositories_spec.rb
+++ b/spec/requests/api/repositories_spec.rb
@@ -3,6 +3,7 @@ require 'spec_helper'
describe API::API do
include ApiHelpers
before(:each) { enable_observers }
+ after(:each) {disable_observers}
let(:user) { create(:user) }
let(:user2) { create(:user) }