BigW Consortium Gitlab

Commit d0451a05 by Lin Jen-Shin

Test for Project#builds_for and return empty array for nothing

parent 2c646bb2
...@@ -430,6 +430,9 @@ class Project < ActiveRecord::Base ...@@ -430,6 +430,9 @@ class Project < ActiveRecord::Base
end end
def builds_for(build_name, ref = 'HEAD') def builds_for(build_name, ref = 'HEAD')
ct = commit(ref)
return [] unless ct
sha = commit(ref).sha sha = commit(ref).sha
builds.joins(:pipeline). builds.joins(:pipeline).
......
...@@ -359,11 +359,25 @@ describe Project, models: true do ...@@ -359,11 +359,25 @@ describe Project, models: true do
describe :repository do describe :repository do
let(:project) { create(:project) } let(:project) { create(:project) }
it 'should return valid repo' do it 'returns valid repo' do
expect(project.repository).to be_kind_of(Repository) expect(project.repository).to be_kind_of(Repository)
end end
end end
describe '#builds_for' do
let(:project) { create(:project) }
let(:pipeline) do
create(:ci_pipeline, project: project, sha: project.commit.sha)
end
let(:build) { create(:ci_build, pipeline: pipeline) }
it 'returns builds for a particular ref' do
build_ids = project.builds_for(build.name, build.sha).map(&:id)
expect(build_ids).to eq([build.id])
end
end
describe :default_issues_tracker? do describe :default_issues_tracker? do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:ext_project) { create(:redmine_project) } let(:ext_project) { create(:redmine_project) }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment