Commit 14f78d06 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Modify specs for new project transfer code

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 900d3079
...@@ -147,7 +147,7 @@ describe API::API, api: true do ...@@ -147,7 +147,7 @@ describe API::API, api: true do
describe "POST /groups/:id/projects/:project_id" do describe "POST /groups/:id/projects/:project_id" do
let(:project) { create(:project) } let(:project) { create(:project) }
before(:each) do before(:each) do
project.stub(:transfer).and_return(true) Projects::TransferService.any_instance.stub(execute: true)
Project.stub(:find).and_return(project) Project.stub(:find).and_return(project)
end end
...@@ -160,8 +160,8 @@ describe API::API, api: true do ...@@ -160,8 +160,8 @@ describe API::API, api: true do
context "when authenticated as admin" do context "when authenticated as admin" do
it "should transfer project to group" do it "should transfer project to group" do
project.should_receive(:transfer)
post api("/groups/#{group1.id}/projects/#{project.id}", admin) post api("/groups/#{group1.id}/projects/#{project.id}", admin)
response.status.should == 201
end end
end end
end end
......
require 'spec_helper' require 'spec_helper'
describe ProjectTransferService do describe Projects::TransferService do
before(:each) { enable_observers } before(:each) { enable_observers }
after(:each) {disable_observers} after(:each) {disable_observers}
context 'namespace -> namespace' do let(:user) { create(:user) }
let(:user) { create(:user) } let(:group) { create(:group) }
let(:group) { create(:group) } let(:group2) { create(:group) }
let(:project) { create(:project, namespace: user.namespace) } let(:project) { create(:project, namespace: user.namespace) }
context 'namespace -> namespace' do
before do before do
@result = service.transfer(project, group) group.add_owner(user)
@service = Projects::TransferService.new(project, user, namespace_id: group.id)
@service.gitlab_shell.stub(mv_repository: true)
@result = @service.execute
end end
it { @result.should be_true } it { @result.should be_true }
...@@ -18,16 +22,25 @@ describe ProjectTransferService do ...@@ -18,16 +22,25 @@ describe ProjectTransferService do
end end
context 'namespace -> no namespace' do context 'namespace -> no namespace' do
let(:user) { create(:user) } before do
let(:project) { create(:project, namespace: user.namespace) } group.add_owner(user)
@service = Projects::TransferService.new(project, user, namespace_id: nil)
@service.gitlab_shell.stub(mv_repository: true)
@result = @service.execute
end
it { lambda{service.transfer(project, nil)}.should raise_error(ActiveRecord::RecordInvalid) } it { @result.should be_false }
it { project.namespace.should == user.namespace }
end end
def service context 'namespace -> not allowed namespace' do
service = ProjectTransferService.new before do
service.gitlab_shell.stub(mv_repository: true) @service = Projects::TransferService.new(project, user, namespace_id: group2.id)
service @service.gitlab_shell.stub(mv_repository: true)
@result = @service.execute
end
it { @result.should be_false }
it { project.namespace.should == user.namespace }
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment