diff --git a/app/models/ci/commit.rb b/app/models/ci/commit.rb index a6556690b9a..6d048779cde 100644 --- a/app/models/ci/commit.rb +++ b/app/models/ci/commit.rb @@ -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 diff --git a/app/models/project.rb b/app/models/project.rb index d9334adef78..953b37e3f7a 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -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) diff --git a/spec/models/ci/project_spec.rb b/spec/models/ci/project_spec.rb index 6ccd399e079..466c7afaf1e 100644 --- a/spec/models/ci/project_spec.rb +++ b/spec/models/ci/project_spec.rb @@ -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 diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index cbb49044cd1..ba8897b95d9 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -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 diff --git a/spec/services/ci/register_build_service_spec.rb b/spec/services/ci/register_build_service_spec.rb index ae4239be821..781764627ac 100644 --- a/spec/services/ci/register_build_service_spec.rb +++ b/spec/services/ci/register_build_service_spec.rb @@ -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