1 # == Schema Information
5 # id :integer not null, primary key
9 # created_at :datetime not null
10 # updated_at :datetime not null
12 # default_branch :string(255)
13 # issues_enabled :boolean default(TRUE), not null
14 # wall_enabled :boolean default(TRUE), not null
15 # merge_requests_enabled :boolean default(TRUE), not null
16 # wiki_enabled :boolean default(TRUE), not null
17 # namespace_id :integer
18 # public :boolean default(FALSE), not null
19 # issues_tracker :string(255) default("gitlab"), not null
20 # issues_tracker_id :string(255)
21 # snippets_enabled :boolean default(TRUE), not null
22 # last_activity_at :datetime
28 describe "Associations" do
29 it { should belong_to(:group) }
30 it { should belong_to(:namespace) }
31 it { should belong_to(:creator).class_name('User') }
32 it { should have_many(:users) }
33 it { should have_many(:events).dependent(:destroy) }
34 it { should have_many(:merge_requests).dependent(:destroy) }
35 it { should have_many(:issues).dependent(:destroy) }
36 it { should have_many(:milestones).dependent(:destroy) }
37 it { should have_many(:users_projects).dependent(:destroy) }
38 it { should have_many(:notes).dependent(:destroy) }
39 it { should have_many(:snippets).dependent(:destroy) }
40 it { should have_many(:deploy_keys).dependent(:destroy) }
41 it { should have_many(:hooks).dependent(:destroy) }
42 it { should have_many(:wikis).dependent(:destroy) }
43 it { should have_many(:protected_branches).dependent(:destroy) }
46 describe "Mass assignment" do
47 it { should_not allow_mass_assignment_of(:namespace_id) }
48 it { should_not allow_mass_assignment_of(:creator_id) }
51 describe "Validation" do
52 let!(:project) { create(:project) }
54 it { should validate_presence_of(:name) }
55 it { should validate_uniqueness_of(:name) }
56 it { should ensure_length_of(:name).is_within(0..255) }
58 it { should validate_presence_of(:path) }
59 it { should validate_uniqueness_of(:path) }
60 it { should ensure_length_of(:path).is_within(0..255) }
61 it { should ensure_length_of(:description).is_within(0..2000) }
62 it { should validate_presence_of(:creator) }
63 it { should ensure_inclusion_of(:issues_enabled).in_array([true, false]) }
64 it { should ensure_inclusion_of(:wall_enabled).in_array([true, false]) }
65 it { should ensure_inclusion_of(:merge_requests_enabled).in_array([true, false]) }
66 it { should ensure_inclusion_of(:wiki_enabled).in_array([true, false]) }
67 it { should ensure_length_of(:issues_tracker_id).is_within(0..255) }
69 it "should not allow new projects beyond user limits" do
70 project.stub(:creator).and_return(double(can_create_project?: false, projects_limit: 1))
71 project.should_not be_valid
72 project.errors[:limit_reached].first.should match(/Your own projects limit is 1/)
76 describe "Respond to" do
77 it { should respond_to(:url_to_repo) }
78 it { should respond_to(:repo_exists?) }
79 it { should respond_to(:satellite) }
80 it { should respond_to(:update_merge_requests) }
81 it { should respond_to(:execute_hooks) }
82 it { should respond_to(:transfer) }
83 it { should respond_to(:name_with_namespace) }
84 it { should respond_to(:namespace_owner) }
85 it { should respond_to(:owner) }
86 it { should respond_to(:path_with_namespace) }
89 it "should return valid url to repo" do
90 project = Project.new(path: "somewhere")
91 project.url_to_repo.should == Gitlab.config.gitlab_shell.ssh_path_prefix + "somewhere.git"
94 it "returns the full web URL for this repo" do
95 project = Project.new(path: "somewhere")
96 project.web_url.should == "#{Gitlab.config.gitlab.url}/somewhere"
99 describe "last_activity methods" do
100 let(:project) { create(:project) }
101 let(:last_event) { double(created_at: Time.now) }
103 describe "last_activity" do
104 it "should alias last_activity to last_event"do
105 project.stub(last_event: last_event)
106 project.last_activity.should == last_event
110 describe 'last_activity_date' do
111 it 'returns the creation date of the project\'s last event if present' do
112 last_activity_event = create(:event, project: project)
113 project.last_activity_date.to_s(:db).should == last_event.created_at.to_s(:db)
116 it 'returns the project\'s last update date if it has no events' do
117 project.last_activity_date.should == project.updated_at
122 describe :update_merge_requests do
123 let(:project) { create(:project_with_code) }
126 @merge_request = create(:merge_request, project: project)
127 @key = create(:key, user_id: project.owner.id)
130 it "should close merge request if last commit from source branch was pushed to target branch" do
131 @merge_request.reloaded_commits
132 @merge_request.last_commit.id.should == "bcf03b5de6c33f3869ef70d68cf06e679d1d7f9a"
133 project.update_merge_requests("8716fc78f3c65bbf7bcf7b574febd583bc5d2812", "bcf03b5de6c33f3869ef70d68cf06e679d1d7f9a", "refs/heads/stable", @key.user)
134 @merge_request.reload
135 @merge_request.merged?.should be_true
138 it "should update merge request commits with new one if pushed to source branch" do
139 @merge_request.last_commit.should == nil
140 project.update_merge_requests("8716fc78f3c65bbf7bcf7b574febd583bc5d2812", "bcf03b5de6c33f3869ef70d68cf06e679d1d7f9a", "refs/heads/master", @key.user)
141 @merge_request.reload
142 @merge_request.last_commit.id.should == "bcf03b5de6c33f3869ef70d68cf06e679d1d7f9a"
147 describe :find_with_namespace do
148 context 'with namespace' do
150 @group = create :group, name: 'gitlab'
151 @project = create(:project, name: 'gitlab-ci', namespace: @group)
154 it { Project.find_with_namespace('gitlab/gitlab-ci').should == @project }
155 it { Project.find_with_namespace('gitlab-ci').should be_nil }
158 context 'w/o namespace' do
160 @project = create(:project, name: 'gitlab-ci')
163 it { Project.find_with_namespace('gitlab-ci').should == @project }
164 it { Project.find_with_namespace('gitlab/gitlab-ci').should be_nil }
168 describe :to_param do
169 context 'with namespace' do
171 @group = create :group, name: 'gitlab'
172 @project = create(:project, name: 'gitlab-ci', namespace: @group)
175 it { @project.to_param.should == "gitlab/gitlab-ci" }
178 context 'w/o namespace' do
180 @project = create(:project, name: 'gitlab-ci')
183 it { @project.to_param.should == "gitlab-ci" }
187 describe :repository do
188 let(:project) { create(:project) }
190 it "should return valid repo" do
191 project.repository.should be_kind_of(Repository)
195 describe :issue_exists? do
196 let(:project) { create(:project) }
197 let(:existed_issue) { create(:issue, project: project) }
198 let(:not_existed_issue) { create(:issue) }
199 let(:ext_project) { create(:redmine_project) }
201 it "should be true or if used internal tracker and issue exists" do
202 project.issue_exists?(existed_issue.id).should be_true
205 it "should be false or if used internal tracker and issue not exists" do
206 project.issue_exists?(not_existed_issue.id).should be_false
209 it "should always be true if used other tracker" do
210 ext_project.issue_exists?(rand(100)).should be_true
214 describe :used_default_issues_tracker? do
215 let(:project) { create(:project) }
216 let(:ext_project) { create(:redmine_project) }
218 it "should be true if used internal tracker" do
219 project.used_default_issues_tracker?.should be_true
222 it "should be false if used other tracker" do
223 ext_project.used_default_issues_tracker?.should be_false
227 describe :can_have_issues_tracker_id? do
228 let(:project) { create(:project) }
229 let(:ext_project) { create(:redmine_project) }
231 it "should be true for projects with external issues tracker if issues enabled" do
232 ext_project.can_have_issues_tracker_id?.should be_true
235 it "should be false for projects with internal issue tracker if issues enabled" do
236 project.can_have_issues_tracker_id?.should be_false
239 it "should be always false if issues disbled" do
240 project.issues_enabled = false
241 ext_project.issues_enabled = false
243 project.can_have_issues_tracker_id?.should be_false
244 ext_project.can_have_issues_tracker_id?.should be_false
248 describe :open_branches do
249 let(:project) { create(:project_with_code) }
252 project.protected_branches.create(name: 'master')
255 it { project.open_branches.map(&:name).should include('bootstrap') }
256 it { project.open_branches.map(&:name).should_not include('master') }