diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-07-14 11:21:52 +0200 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-07-14 11:21:52 +0200 |
commit | 14fbff00b59ad3aeff7d585039720bb5743b13da (patch) | |
tree | b995c502b81f26c749685fdd7c33ec1b83af236a | |
parent | 613208c360f9f091a9994be2db107a46270e5fe4 (diff) | |
download | gitlab-ce-14fbff00b59ad3aeff7d585039720bb5743b13da.tar.gz |
Add specs for changing default branch in a project
-rw-r--r-- | app/services/projects/update_service.rb | 2 | ||||
-rw-r--r-- | spec/services/projects/update_service_spec.rb | 34 |
2 files changed, 26 insertions, 10 deletions
diff --git a/app/services/projects/update_service.rb b/app/services/projects/update_service.rb index ad71fa2af15..30ca95eef7a 100644 --- a/app/services/projects/update_service.rb +++ b/app/services/projects/update_service.rb @@ -10,7 +10,7 @@ module Projects end if changing_default_branch? - project.change_head(new_branch) + project.change_head(params[:default_branch]) end if project.update_attributes(params.except(:default_branch)) diff --git a/spec/services/projects/update_service_spec.rb b/spec/services/projects/update_service_spec.rb index c974d470ae4..cdf61eb28cf 100644 --- a/spec/services/projects/update_service_spec.rb +++ b/spec/services/projects/update_service_spec.rb @@ -1,11 +1,14 @@ require 'spec_helper' -describe Projects::UpdateService, services: true do +describe Projects::UpdateService, '#execute', :services do let(:user) { create(:user) } let(:admin) { create(:admin) } - let(:project) { create(:empty_project, creator_id: user.id, namespace: user.namespace) } - describe 'update_by_user' do + let(:project) do + create(:empty_project, creator: user, namespace: user.namespace) + end + + context 'when changing visibility level' do context 'when visibility_level is INTERNAL' do it 'updates the project to internal' do result = update_project(project, user, visibility_level: Gitlab::VisibilityLevel::INTERNAL) @@ -55,12 +58,13 @@ describe Projects::UpdateService, services: true do end end - describe 'visibility_level' do + describe 'when updating project that has forks' do let(:project) { create(:empty_project, :internal) } let(:forked_project) { create(:forked_project_with_submodules, :internal) } before do - forked_project.build_forked_project_link(forked_to_project_id: forked_project.id, forked_from_project_id: project.id) + forked_project.build_forked_project_link(forked_to_project_id: forked_project.id, + forked_from_project_id: project.id) forked_project.save end @@ -89,11 +93,23 @@ describe Projects::UpdateService, services: true do end end - it 'returns an error result when record cannot be updated' do - result = update_project(project, admin, { name: 'foo&bar' }) + context 'when updating a default branch' do + let(:project) { create(:project, :repository) } + + it 'changes a default branch' do + update_project(project, admin, default_branch: 'feature') + + expect(Project.find(project.id).default_branch).to eq 'feature' + end + end + + context 'when passing invalid parameters' do + it 'returns an error result when record cannot be updated' do + result = update_project(project, admin, { name: 'foo&bar' }) - expect(result).to eq({ status: :error, - message: 'Project could not be updated!' }) + expect(result).to eq({ status: :error, + message: 'Project could not be updated!' }) + end end def update_project(project, user, opts) |