diff --git a/app/models/ci/project.rb b/app/models/ci/project.rb index 9c9198302f6..c9e5707f218 100644 --- a/app/models/ci/project.rb +++ b/app/models/ci/project.rb @@ -28,9 +28,11 @@ module Ci class Project < ActiveRecord::Base extend Ci::Model - + include Ci::ProjectStatus + belongs_to :gl_project, class_name: 'Project', foreign_key: :gitlab_id + has_many :commits, ->() { order(:committed_at) }, dependent: :destroy, class_name: 'Ci::Commit' has_many :builds, through: :commits, dependent: :destroy, class_name: 'Ci::Build' has_many :runner_projects, dependent: :destroy, class_name: 'Ci::RunnerProject' diff --git a/spec/factories/ci/projects.rb b/spec/factories/ci/projects.rb index e6be88fa585..e6bd0685f8d 100644 --- a/spec/factories/ci/projects.rb +++ b/spec/factories/ci/projects.rb @@ -43,7 +43,7 @@ FactoryGirl.define do "git@demo.gitlab.com:gitlab/gitlab-shell#{n}.git" end - sequence :gitlab_id + gl_project factory: :project factory :ci_project do token 'iPWx6WM4lhHNedGfBpPJNP' diff --git a/spec/features/ci/builds_spec.rb b/spec/features/ci/builds_spec.rb index ddfc579d1b8..2f020e524e2 100644 --- a/spec/features/ci/builds_spec.rb +++ b/spec/features/ci/builds_spec.rb @@ -1,57 +1,60 @@ require 'spec_helper' describe "Builds" do - before do - @project = FactoryGirl.create :project - @commit = FactoryGirl.create :commit, project: @project - @build = FactoryGirl.create :build, commit: @commit - end - - describe "GET /:project/builds/:id" do + context :private_project do before do + @project = FactoryGirl.create :ci_project + @commit = FactoryGirl.create :ci_commit, project: @project + @build = FactoryGirl.create :ci_build, commit: @commit login_as :user - visit project_build_path(@project, @build) + @project.gl_project.team << [@user, :master] end - it { expect(page).to have_content @commit.sha[0..7] } - it { expect(page).to have_content @commit.git_commit_message } - it { expect(page).to have_content @commit.git_author_name } + describe "GET /:project/builds/:id" do + before do + visit ci_project_build_path(@project, @build) + end + + it { expect(page).to have_content @commit.sha[0..7] } + it { expect(page).to have_content @commit.git_commit_message } + it { expect(page).to have_content @commit.git_author_name } + end + + describe "GET /:project/builds/:id/cancel" do + before do + @build.run! + visit cancel_ci_project_build_path(@project, @build) + end + + it { expect(page).to have_content 'canceled' } + it { expect(page).to have_content 'Retry' } + end + + describe "POST /:project/builds/:id/retry" do + before do + @build.cancel! + visit ci_project_build_path(@project, @build) + click_link 'Retry' + end + + it { expect(page).to have_content 'pending' } + it { expect(page).to have_content 'Cancel' } + end end - describe "GET /:project/builds/:id/cancel" do - before do - login_as :user - @build.run! - visit cancel_project_build_path(@project, @build) + context :public_project do + describe "Show page public accessible" do + before do + @project = FactoryGirl.create :ci_public_project + @commit = FactoryGirl.create :ci_commit, project: @project + @runner = FactoryGirl.create :ci_specific_runner + @build = FactoryGirl.create :ci_build, commit: @commit, runner: @runner + + stub_gitlab_calls + visit ci_project_build_path(@project, @build) + end + + it { expect(page).to have_content @commit.sha[0..7] } end - - it { expect(page).to have_content 'canceled' } - it { expect(page).to have_content 'Retry' } - end - - describe "POST /:project/builds/:id/retry" do - before do - login_as :user - @build.cancel! - visit project_build_path(@project, @build) - click_link 'Retry' - end - - it { expect(page).to have_content 'pending' } - it { expect(page).to have_content 'Cancel' } - end - - describe "Show page public accessible" do - before do - @project = FactoryGirl.create :public_project - @commit = FactoryGirl.create :commit, project: @project - @runner = FactoryGirl.create :specific_runner - @build = FactoryGirl.create :build, commit: @commit, runner: @runner - - stub_gitlab_calls - visit project_build_path(@project, @build) - end - - it { expect(page).to have_content @commit.sha[0..7] } end end