2012-02-15 21:02:33 +01:00
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: protected_branches
|
|
|
|
#
|
2012-06-26 20:23:09 +02:00
|
|
|
# id :integer(4) not null, primary key
|
|
|
|
# project_id :integer(4) not null
|
2012-02-15 21:02:33 +01:00
|
|
|
# name :string(255) not null
|
|
|
|
# created_at :datetime not null
|
|
|
|
# updated_at :datetime not null
|
|
|
|
#
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe ProtectedBranch do
|
2012-05-11 00:43:12 +02:00
|
|
|
let(:project) { Factory(:project) }
|
|
|
|
|
|
|
|
describe 'Associations' do
|
|
|
|
it { should belong_to(:project) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'Validation' do
|
|
|
|
it { should validate_presence_of(:project_id) }
|
|
|
|
it { should validate_presence_of(:name) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'Callbacks' do
|
|
|
|
subject { ProtectedBranch.new(:project => project, :name => 'branch_name') }
|
|
|
|
|
|
|
|
it 'call update_repository after save' do
|
|
|
|
subject.should_receive(:update_repository)
|
|
|
|
subject.save
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'call update_repository after destroy' do
|
|
|
|
subject.should_receive(:update_repository)
|
|
|
|
subject.destroy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#update_repository' do
|
|
|
|
let(:gitolite) { mock }
|
|
|
|
|
|
|
|
subject { ProtectedBranch.new(:project => project) }
|
|
|
|
|
|
|
|
it "updates the branch's project repo permissions" do
|
2012-05-26 12:37:49 +02:00
|
|
|
Gitlab::GitHost.should_receive(:system).and_return(gitolite)
|
2012-05-11 00:43:12 +02:00
|
|
|
gitolite.should_receive(:update_project).with(project.path, project)
|
|
|
|
|
|
|
|
subject.update_repository
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#commit' do
|
|
|
|
subject { ProtectedBranch.new(:project => project, :name => 'cant_touch_this') }
|
|
|
|
|
|
|
|
it 'commits itself to its project' do
|
|
|
|
project.should_receive(:commit).with('cant_touch_this')
|
|
|
|
|
|
|
|
subject.commit
|
|
|
|
end
|
|
|
|
end
|
2012-02-15 21:02:33 +01:00
|
|
|
end
|