Commit 14fbff00 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Add specs for changing default branch in a project

parent 613208c3
...@@ -10,7 +10,7 @@ module Projects ...@@ -10,7 +10,7 @@ module Projects
end end
if changing_default_branch? if changing_default_branch?
project.change_head(new_branch) project.change_head(params[:default_branch])
end end
if project.update_attributes(params.except(:default_branch)) if project.update_attributes(params.except(:default_branch))
......
require 'spec_helper' require 'spec_helper'
describe Projects::UpdateService, services: true do describe Projects::UpdateService, '#execute', :services do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:admin) { create(:admin) } 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 context 'when visibility_level is INTERNAL' do
it 'updates the project to internal' do it 'updates the project to internal' do
result = update_project(project, user, visibility_level: Gitlab::VisibilityLevel::INTERNAL) result = update_project(project, user, visibility_level: Gitlab::VisibilityLevel::INTERNAL)
...@@ -55,12 +58,13 @@ describe Projects::UpdateService, services: true do ...@@ -55,12 +58,13 @@ describe Projects::UpdateService, services: true do
end end
end end
describe 'visibility_level' do describe 'when updating project that has forks' do
let(:project) { create(:empty_project, :internal) } let(:project) { create(:empty_project, :internal) }
let(:forked_project) { create(:forked_project_with_submodules, :internal) } let(:forked_project) { create(:forked_project_with_submodules, :internal) }
before do 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 forked_project.save
end end
...@@ -89,11 +93,23 @@ describe Projects::UpdateService, services: true do ...@@ -89,11 +93,23 @@ describe Projects::UpdateService, services: true do
end end
end end
it 'returns an error result when record cannot be updated' do context 'when updating a default branch' do
result = update_project(project, admin, { name: 'foo&bar' }) 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, expect(result).to eq({ status: :error,
message: 'Project could not be updated!' }) message: 'Project could not be updated!' })
end
end end
def update_project(project, user, opts) def update_project(project, user, opts)
......
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