#214: added specs for Project #restore_branch && #delete_branch
This commit is contained in:
parent
225da758ec
commit
7880fa4625
|
@ -40,7 +40,7 @@ class Projects::Git::TreesController < Projects::Git::BaseController
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
if @branch && @project.default_branch != @branch.name && @project.delete_branch(@branch, current_user).present?
|
if @branch && @project.delete_branch(@branch, current_user)
|
||||||
render :nothing => true
|
render :nothing => true
|
||||||
else
|
else
|
||||||
render :nothing => true, :status => 422
|
render :nothing => true, :status => 422
|
||||||
|
|
|
@ -39,8 +39,12 @@ module Modules
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete_branch(branch, user)
|
def delete_branch(branch, user)
|
||||||
|
return false if default_branch == branch.name
|
||||||
message = repo.git.native(:branch, {}, '-D', branch.name)
|
message = repo.git.native(:branch, {}, '-D', branch.name)
|
||||||
Resque.enqueue(GitHook,owner.uname, name, GitHook::ZERO, branch.commit.id, "refs/heads/#{branch.name}", 'commit', "user-#{user.id}", message)
|
if message.present?
|
||||||
|
Resque.enqueue(GitHook,owner.uname, name, GitHook::ZERO, branch.commit.id, "refs/heads/#{branch.name}", 'commit', "user-#{user.id}", message)
|
||||||
|
end
|
||||||
|
return message.present?
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_file(path, data, options = {})
|
def update_file(path, data, options = {})
|
||||||
|
|
|
@ -86,4 +86,55 @@ describe Project do
|
||||||
lambda {FactoryGirl.create(:project, :name => "...\nbeatiful_name\n for project")}.should raise_error(ActiveRecord::RecordInvalid)
|
lambda {FactoryGirl.create(:project, :name => "...\nbeatiful_name\n for project")}.should raise_error(ActiveRecord::RecordInvalid)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'manage branches' do
|
||||||
|
let!(:project) { FactoryGirl.create(:project_with_commit) }
|
||||||
|
let(:branch) { project.repo.branches.detect{|b| b.name == 'conflicts'} }
|
||||||
|
let(:master) { project.repo.branches.detect{|b| b.name == 'master'} }
|
||||||
|
let(:user) { FactoryGirl.create(:user) }
|
||||||
|
before { stub_redis }
|
||||||
|
|
||||||
|
context '#delete_branch' do
|
||||||
|
it 'ensures that returns true on success' do
|
||||||
|
project.delete_branch(branch, user).should be_true
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'ensures that branch has been deleted' do
|
||||||
|
lambda { project.delete_branch(branch, user) }.should change{ project.repo.branches.count }.by(-1)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'ensures that returns false on delete master' do
|
||||||
|
project.delete_branch(master, user).should be_false
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'ensures that master has not been deleted' do
|
||||||
|
lambda { project.delete_branch(master, user) }.should change{ project.repo.branches.count }.by(0)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'ensures that returns false on delete wrong branch' do
|
||||||
|
project.delete_branch(branch, user)
|
||||||
|
project.delete_branch(branch, user).should be_false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context '#restore_branch' do
|
||||||
|
before do
|
||||||
|
project.delete_branch(branch, user)
|
||||||
|
end
|
||||||
|
|
||||||
|
xit 'ensures that returns true on success' do
|
||||||
|
project.restore_branch(branch.name, branch.commit.id).should be_true
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'ensures that branch has been restored' do
|
||||||
|
lambda { project.restore_branch(branch.name, branch.commit.id) }.should change{ project.repo.branches.count }.by(1)
|
||||||
|
end
|
||||||
|
|
||||||
|
xit 'ensures that returns false on restore wrong branch' do
|
||||||
|
project.restore_branch(branch.name, GitHook::ZERO).should be_false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue