Commit d50446088c05409604f8daad0879a23b3c5f5e8f
1 parent
9e5c0168
Exists in
master
and in
4 other branches
Add spec for ProtectedBranch.
Showing
1 changed file
with
47 additions
and
1 deletions
Show diff stats
spec/models/protected_branch_spec.rb
... | ... | @@ -12,5 +12,51 @@ |
12 | 12 | require 'spec_helper' |
13 | 13 | |
14 | 14 | describe ProtectedBranch do |
15 | - pending "add some examples to (or delete) #{__FILE__}" | |
15 | + let(:project) { Factory(:project) } | |
16 | + | |
17 | + describe 'Associations' do | |
18 | + it { should belong_to(:project) } | |
19 | + end | |
20 | + | |
21 | + describe 'Validation' do | |
22 | + it { should validate_presence_of(:project_id) } | |
23 | + it { should validate_presence_of(:name) } | |
24 | + end | |
25 | + | |
26 | + describe 'Callbacks' do | |
27 | + subject { ProtectedBranch.new(:project => project, :name => 'branch_name') } | |
28 | + | |
29 | + it 'call update_repository after save' do | |
30 | + subject.should_receive(:update_repository) | |
31 | + subject.save | |
32 | + end | |
33 | + | |
34 | + it 'call update_repository after destroy' do | |
35 | + subject.should_receive(:update_repository) | |
36 | + subject.destroy | |
37 | + end | |
38 | + end | |
39 | + | |
40 | + describe '#update_repository' do | |
41 | + let(:gitolite) { mock } | |
42 | + | |
43 | + subject { ProtectedBranch.new(:project => project) } | |
44 | + | |
45 | + it "updates the branch's project repo permissions" do | |
46 | + Gitlabhq::GitHost.should_receive(:system).and_return(gitolite) | |
47 | + gitolite.should_receive(:update_project).with(project.path, project) | |
48 | + | |
49 | + subject.update_repository | |
50 | + end | |
51 | + end | |
52 | + | |
53 | + describe '#commit' do | |
54 | + subject { ProtectedBranch.new(:project => project, :name => 'cant_touch_this') } | |
55 | + | |
56 | + it 'commits itself to its project' do | |
57 | + project.should_receive(:commit).with('cant_touch_this') | |
58 | + | |
59 | + subject.commit | |
60 | + end | |
61 | + end | |
16 | 62 | end | ... | ... |