diff --git a/app/models/ci/project.rb b/app/models/ci/project.rb index ba6e320426c10fe708716e189fa32855574c879c..77cce261fc80ab08be84cfbfb7768887ad15a42f 100644 --- a/app/models/ci/project.rb +++ b/app/models/ci/project.rb @@ -48,8 +48,6 @@ class Project < ActiveRecord::Base accepts_nested_attributes_for :variables, allow_destroy: true - delegate :commits, :builds, to: :gl_project - # # Validations # @@ -210,5 +208,13 @@ def gitlab_url def setup_finished? commits.any? end + + def commits + gl_project.ci_commits + end + + def builds + gl_project.ci_builds + end end end diff --git a/app/models/project.rb b/app/models/project.rb index a5393d396f8d2bed49294707846deea91f759b28..d9334adef78f0db8da07d784877e2b8de1cfbc18 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -118,8 +118,8 @@ def set_last_activity_at has_many :deploy_keys, through: :deploy_keys_projects has_many :users_star_projects, dependent: :destroy has_many :starrers, through: :users_star_projects, source: :user - has_many :commits, ->() { order('CASE WHEN ci_commits.committed_at IS NULL THEN 0 ELSE 1 END', :committed_at, :id) }, dependent: :destroy, class_name: 'Ci::Commit', foreign_key: :gl_project_id - has_many :builds, through: :commits, dependent: :destroy, class_name: 'Ci::Build' + has_many :ci_commits, ->() { order('CASE WHEN ci_commits.committed_at IS NULL THEN 0 ELSE 1 END', :committed_at, :id) }, dependent: :destroy, class_name: 'Ci::Commit', foreign_key: :gl_project_id + has_many :ci_builds, through: :ci_commits, source: :builds, dependent: :destroy, class_name: 'Ci::Build' has_one :import_data, dependent: :destroy, class_name: "ProjectImportData" has_one :gitlab_ci_project, dependent: :destroy, class_name: "Ci::Project", foreign_key: :gitlab_id diff --git a/spec/models/ci/project_spec.rb b/spec/models/ci/project_spec.rb index fe12160659ce98231e2fdbf2a81779a6246ac58d..6ccd399e0798950d493cb277bbeecc89f3653c32 100644 --- a/spec/models/ci/project_spec.rb +++ b/spec/models/ci/project_spec.rb @@ -75,7 +75,7 @@ it 'returns ordered list of commits' do commit1 = FactoryGirl.create :ci_commit, committed_at: 1.hour.ago, gl_project: project commit2 = FactoryGirl.create :ci_commit, committed_at: 2.hour.ago, gl_project: project - expect(project.commits).to eq([commit2, commit1]) + expect(project.ci_commits).to eq([commit2, commit1]) end it 'returns commits ordered by committed_at and id, with nulls last' do @@ -83,7 +83,7 @@ commit2 = FactoryGirl.create :ci_commit, committed_at: nil, gl_project: project commit3 = FactoryGirl.create :ci_commit, committed_at: 2.hour.ago, gl_project: project commit4 = FactoryGirl.create :ci_commit, committed_at: nil, gl_project: project - expect(project.commits).to eq([commit2, commit4, commit3, commit1]) + expect(project.ci_commits).to eq([commit2, commit4, commit3, commit1]) end end