Make ensure_gitlab_ci_project return ci_project or create a new one

This commit is contained in:
Kamil Trzcinski 2015-09-29 10:44:53 +02:00
parent 9498a40052
commit 0d877d91e7
5 changed files with 9 additions and 16 deletions

View file

@ -37,11 +37,7 @@ module Ci
end
def project
unless @project
gl_project.ensure_ci_project
@project = gl_project.gitlab_ci_project
end
@project
@project ||= gl_project.ensure_gitlab_ci_project
end
def project_id

View file

@ -747,10 +747,8 @@ class Project < ActiveRecord::Base
gitlab_ci_project.commits.find_by(sha: sha) if gitlab_ci?
end
def ensure_ci_project
unless gitlab_ci_project
create_gitlab_ci_project
end
def ensure_gitlab_ci_project
gitlab_ci_project || create_gitlab_ci_project
end
def enable_ci(user)

View file

@ -56,16 +56,16 @@ describe Ci::Project do
describe "ordered_by_last_commit_date" do
it "returns ordered projects" do
newest_project = FactoryGirl.create :empty_project
newest_project.ensure_ci_project
newest_ci_project = newest_project.ensure_gitlab_ci_project
oldest_project = FactoryGirl.create :empty_project
oldest_project.ensure_ci_project
oldest_ci_project = oldest_project.ensure_gitlab_ci_project
project_without_commits = FactoryGirl.create :empty_project
project_without_commits.ensure_ci_project
ci_project_without_commits = project_without_commits.ensure_gitlab_ci_project
FactoryGirl.create :ci_commit, committed_at: 1.hour.ago, gl_project: newest_project
FactoryGirl.create :ci_commit, committed_at: 2.hour.ago, gl_project: oldest_project
expect(Ci::Project.ordered_by_last_commit_date).to eq([newest_project.gitlab_ci_project, oldest_project.gitlab_ci_project, project_without_commits.gitlab_ci_project])
expect(Ci::Project.ordered_by_last_commit_date).to eq([newest_ci_project, oldest_ci_project, ci_project_without_commits])
end
end

View file

@ -407,7 +407,7 @@ describe Project do
let(:commit) { create :ci_commit, gl_project: project }
before do
project.ensure_ci_project
project.ensure_gitlab_ci_project
project.create_gitlab_ci_service(active: true)
end

View file

@ -10,8 +10,7 @@ module Ci
let!(:specific_runner) { FactoryGirl.create(:ci_runner, is_shared: false) }
before do
gl_project.ensure_ci_project
specific_runner.assign_to(gl_project.gitlab_ci_project)
specific_runner.assign_to(gl_project.ensure_gitlab_ci_project)
end
describe :execute do