protected_branch_spec.rb 1.18 KB
Newer Older
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
1 2 3 4
# == Schema Information
#
# Table name: protected_branches
#
5 6 7 8 9
#  id         :integer          not null, primary key
#  project_id :integer          not null
#  name       :string(255)      not null
#  created_at :datetime         not null
#  updated_at :datetime         not null
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
10 11
#

12 13 14
require 'spec_helper'

describe ProtectedBranch do
Robb Kidd's avatar
Robb Kidd committed
15 16 17 18
  describe 'Associations' do
    it { should belong_to(:project) }
  end

19 20 21 22
  describe "Mass assignment" do
    it { should_not allow_mass_assignment_of(:project_id) }
  end

Robb Kidd's avatar
Robb Kidd committed
23
  describe 'Validation' do
Andrey Kumanyaev's avatar
Andrey Kumanyaev committed
24
    it { should validate_presence_of(:project) }
Robb Kidd's avatar
Robb Kidd committed
25 26 27 28
    it { should validate_presence_of(:name) }
  end

  describe 'Callbacks' do
29
    let(:branch) { build(:protected_branch) }
Robb Kidd's avatar
Robb Kidd committed
30 31

    it 'call update_repository after save' do
32 33
      branch.should_receive(:update_repository)
      branch.save
Robb Kidd's avatar
Robb Kidd committed
34 35 36
    end

    it 'call update_repository after destroy' do
37 38 39
      branch.save
      branch.should_receive(:update_repository)
      branch.destroy
Robb Kidd's avatar
Robb Kidd committed
40 41 42 43
    end
  end

  describe '#commit' do
44
    let(:branch) { create(:protected_branch) }
Robb Kidd's avatar
Robb Kidd committed
45 46

    it 'commits itself to its project' do
47
      branch.project.repository.should_receive(:commit).with(branch.name)
48
      branch.commit
Robb Kidd's avatar
Robb Kidd committed
49 50
    end
  end
51
end