1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
# == Schema Information
#
# Table name: projects
#
# id :integer not null, primary key
# name :string(255) not null
# timeout :integer default(1800), not null
# scripts :text not null
# created_at :datetime
# updated_at :datetime
# token :string(255)
# default_ref :string(255)
# gitlab_url :string(255)
# always_build :boolean default(FALSE), not null
# polling_interval :integer
# public :boolean default(FALSE), not null
# ssh_url_to_repo :string(255)
# gitlab_id :integer
# allow_git_fetch :boolean default(TRUE), not null
# email_recipients :string(255) default(""), not null
# email_add_committer :boolean default(TRUE), not null
# email_only_broken_builds :boolean default(TRUE), not null
#
require 'spec_helper'
describe Project do
subject { FactoryGirl.build :project }
it { should have_many(:commits) }
it { should validate_presence_of :name }
it { should validate_presence_of :scripts }
it { should validate_presence_of :timeout }
it { should validate_presence_of :default_ref }
describe 'before_validation' do
it 'should set an random token if none provided' do
project = FactoryGirl.create :project_without_token
project.token.should_not == ""
end
it 'should not set an random toke if one provided' do
project = FactoryGirl.create :project
project.token.should == "iPWx6WM4lhHNedGfBpPJNP"
end
end
context :valid_project do
let(:project) { FactoryGirl.create :project }
context :project_with_commit_and_builds do
before do
commit = FactoryGirl.create(:commit, project: project)
FactoryGirl.create(:build, commit: commit)
end
it { project.status.should == 'pending' }
it { project.last_build.should be_kind_of(Build) }
it { project.human_status.should == 'pending' }
end
end
describe '#email_notification?' do
it do
project = FactoryGirl.create :project, email_add_committer: true
project.email_notification?.should == true
end
it do
project = FactoryGirl.create :project, email_add_committer: false, email_recipients: 'test tesft'
project.email_notification?.should == true
end
it do
project = FactoryGirl.create :project, email_add_committer: false, email_recipients: ''
project.email_notification?.should == false
end
end
describe '#broken_or_success?' do
it {
project = FactoryGirl.create :project, email_add_committer: true
project.stub(:broken?).and_return(true)
project.stub(:success?).and_return(true)
project.broken_or_success?.should == true
}
it {
project = FactoryGirl.create :project, email_add_committer: true
project.stub(:broken?).and_return(true)
project.stub(:success?).and_return(false)
project.broken_or_success?.should == true
}
it {
project = FactoryGirl.create :project, email_add_committer: true
project.stub(:broken?).and_return(false)
project.stub(:success?).and_return(true)
project.broken_or_success?.should == true
}
it {
project = FactoryGirl.create :project, email_add_committer: true
project.stub(:broken?).and_return(false)
project.stub(:success?).and_return(false)
project.broken_or_success?.should == false
}
end
describe 'Project.parse' do
let(:project_dump) { File.read(Rails.root.join('spec/support/gitlab_stubs/raw_project.yml')) }
let(:parsed_project) { Project.parse(project_dump) }
it { parsed_project.should be_valid }
it { parsed_project.should be_kind_of(Project) }
it { parsed_project.name.should eq("GitLab / api.gitlab.org") }
it { parsed_project.gitlab_id.should eq(189) }
it { parsed_project.gitlab_url.should eq("http://localhost:3000/gitlab/api-gitlab-org") }
end
end
# == Schema Information
#
# Table name: projects
#
# id :integer not null, primary key
# name :string(255) not null
# timeout :integer default(1800), not null
# scripts :text default(""), not null
# created_at :datetime not null
# updated_at :datetime not null
# token :string(255)
# default_ref :string(255)
# gitlab_url :string(255)
# always_build :boolean default(FALSE), not null
# polling_interval :integer
# public :boolean default(FALSE), not null
# ssh_url_to_repo :string(255)
# gitlab_id :integer
# allow_git_fetch :boolean default(TRUE), not null
# email_recipients :string(255)
# email_add_committer :boolean default(TRUE), not null
# email_only_breaking_build :boolean default(TRUE), not null
#
|