diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-05-28 19:04:18 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-05-28 19:04:18 +0300 |
commit | 14f78d067d703c20b788498cd90c40903ba9f84e (patch) | |
tree | ce5c66a0862b6f1ed425b183325933d5018c47f3 /spec | |
parent | 900d30798b7eef1301978ff6f97b4cee7414b696 (diff) | |
download | gitlab-ce-14f78d067d703c20b788498cd90c40903ba9f84e.tar.gz |
Modify specs for new project transfer code
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'spec')
-rw-r--r-- | spec/requests/api/groups_spec.rb | 4 | ||||
-rw-r--r-- | spec/services/projects/transfer_service_spec.rb | 41 |
2 files changed, 29 insertions, 16 deletions
diff --git a/spec/requests/api/groups_spec.rb b/spec/requests/api/groups_spec.rb index 6fcab85335a..f27a60e4bc0 100644 --- a/spec/requests/api/groups_spec.rb +++ b/spec/requests/api/groups_spec.rb @@ -147,7 +147,7 @@ describe API::API, api: true do describe "POST /groups/:id/projects/:project_id" do let(:project) { create(:project) } before(:each) do - project.stub(:transfer).and_return(true) + Projects::TransferService.any_instance.stub(execute: true) Project.stub(:find).and_return(project) end @@ -160,8 +160,8 @@ describe API::API, api: true do context "when authenticated as admin" do it "should transfer project to group" do - project.should_receive(:transfer) post api("/groups/#{group1.id}/projects/#{project.id}", admin) + response.status.should == 201 end end end diff --git a/spec/services/projects/transfer_service_spec.rb b/spec/services/projects/transfer_service_spec.rb index 109b429967e..563a8b0c01c 100644 --- a/spec/services/projects/transfer_service_spec.rb +++ b/spec/services/projects/transfer_service_spec.rb @@ -1,16 +1,20 @@ require 'spec_helper' -describe ProjectTransferService do +describe Projects::TransferService do before(:each) { enable_observers } after(:each) {disable_observers} - context 'namespace -> namespace' do - let(:user) { create(:user) } - let(:group) { create(:group) } - let(:project) { create(:project, namespace: user.namespace) } + let(:user) { create(:user) } + let(:group) { create(:group) } + let(:group2) { create(:group) } + let(:project) { create(:project, namespace: user.namespace) } + context 'namespace -> namespace' 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 it { @result.should be_true } @@ -18,16 +22,25 @@ describe ProjectTransferService do end context 'namespace -> no namespace' do - let(:user) { create(:user) } - let(:project) { create(:project, namespace: user.namespace) } + before do + 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 - def service - service = ProjectTransferService.new - service.gitlab_shell.stub(mv_repository: true) - service + context 'namespace -> not allowed namespace' do + before do + @service = Projects::TransferService.new(project, user, namespace_id: group2.id) + @service.gitlab_shell.stub(mv_repository: true) + @result = @service.execute + end + + it { @result.should be_false } + it { project.namespace.should == user.namespace } end end - |