Commit 0d877d91 authored by Kamil Trzcinski's avatar Kamil Trzcinski

Make ensure_gitlab_ci_project return ci_project or create a new one

parent 9498a400
......@@ -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
......
......@@ -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)
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
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