Commit 2c3355f9 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'ci-commits-to-projects' into 'master'

Make Ci::Commits belong to Project instead of Ci::Project



See merge request !1455
parents bdf46685 0d877d91
...@@ -30,7 +30,6 @@ module Ci ...@@ -30,7 +30,6 @@ module Ci
LAZY_ATTRIBUTES = ['trace'] LAZY_ATTRIBUTES = ['trace']
belongs_to :commit, class_name: 'Ci::Commit' belongs_to :commit, class_name: 'Ci::Commit'
belongs_to :project, class_name: 'Ci::Project'
belongs_to :runner, class_name: 'Ci::Runner' belongs_to :runner, class_name: 'Ci::Runner'
belongs_to :trigger_request, class_name: 'Ci::TriggerRequest' belongs_to :trigger_request, class_name: 'Ci::TriggerRequest'
...@@ -80,7 +79,6 @@ module Ci ...@@ -80,7 +79,6 @@ module Ci
new_build.commands = build.commands new_build.commands = build.commands
new_build.tag_list = build.tag_list new_build.tag_list = build.tag_list
new_build.commit_id = build.commit_id new_build.commit_id = build.commit_id
new_build.project_id = build.project_id
new_build.name = build.name new_build.name = build.name
new_build.allow_failure = build.allow_failure new_build.allow_failure = build.allow_failure
new_build.stage = build.stage new_build.stage = build.stage
...@@ -137,7 +135,7 @@ module Ci ...@@ -137,7 +135,7 @@ module Ci
state :canceled, value: 'canceled' state :canceled, value: 'canceled'
end end
delegate :sha, :short_sha, :before_sha, :ref, delegate :sha, :short_sha, :before_sha, :ref, :project,
to: :commit, prefix: false to: :commit, prefix: false
def trace_html def trace_html
...@@ -188,7 +186,7 @@ module Ci ...@@ -188,7 +186,7 @@ module Ci
end end
def project_id def project_id
commit.project_id commit.project.id
end end
def project_name def project_name
......
...@@ -19,7 +19,7 @@ module Ci ...@@ -19,7 +19,7 @@ module Ci
class Commit < ActiveRecord::Base class Commit < ActiveRecord::Base
extend Ci::Model extend Ci::Model
belongs_to :project, class_name: 'Ci::Project' belongs_to :gl_project, class_name: '::Project', foreign_key: :gl_project_id
has_many :builds, dependent: :destroy, class_name: 'Ci::Build' has_many :builds, dependent: :destroy, class_name: 'Ci::Build'
has_many :trigger_requests, dependent: :destroy, class_name: 'Ci::TriggerRequest' has_many :trigger_requests, dependent: :destroy, class_name: 'Ci::TriggerRequest'
...@@ -36,6 +36,14 @@ module Ci ...@@ -36,6 +36,14 @@ module Ci
sha sha
end end
def project
@project ||= gl_project.ensure_gitlab_ci_project
end
def project_id
project.id
end
def last_build def last_build
builds.order(:id).last builds.order(:id).last
end end
...@@ -111,7 +119,6 @@ module Ci ...@@ -111,7 +119,6 @@ module Ci
builds_attrs = config_processor.builds_for_stage_and_ref(stage, ref, tag) builds_attrs = config_processor.builds_for_stage_and_ref(stage, ref, tag)
builds_attrs.map do |build_attrs| builds_attrs.map do |build_attrs|
builds.create!({ builds.create!({
project: project,
name: build_attrs[:name], name: build_attrs[:name],
commands: build_attrs[:script], commands: build_attrs[:script],
tag_list: build_attrs[:tags], tag_list: build_attrs[:tags],
......
...@@ -33,15 +33,12 @@ module Ci ...@@ -33,15 +33,12 @@ module Ci
belongs_to :gl_project, class_name: '::Project', foreign_key: :gitlab_id belongs_to :gl_project, class_name: '::Project', foreign_key: :gitlab_id
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'
has_many :builds, through: :commits, dependent: :destroy, class_name: 'Ci::Build'
has_many :runner_projects, dependent: :destroy, class_name: 'Ci::RunnerProject' has_many :runner_projects, dependent: :destroy, class_name: 'Ci::RunnerProject'
has_many :runners, through: :runner_projects, class_name: 'Ci::Runner' has_many :runners, through: :runner_projects, class_name: 'Ci::Runner'
has_many :web_hooks, dependent: :destroy, class_name: 'Ci::WebHook' has_many :web_hooks, dependent: :destroy, class_name: 'Ci::WebHook'
has_many :events, dependent: :destroy, class_name: 'Ci::Event' has_many :events, dependent: :destroy, class_name: 'Ci::Event'
has_many :variables, dependent: :destroy, class_name: 'Ci::Variable' has_many :variables, dependent: :destroy, class_name: 'Ci::Variable'
has_many :triggers, dependent: :destroy, class_name: 'Ci::Trigger' has_many :triggers, dependent: :destroy, class_name: 'Ci::Trigger'
has_one :last_commit, -> { order 'ci_commits.created_at DESC' }, class_name: 'Ci::Commit'
# Project services # Project services
has_many :services, dependent: :destroy, class_name: 'Ci::Service' has_many :services, dependent: :destroy, class_name: 'Ci::Service'
...@@ -104,8 +101,8 @@ module Ci ...@@ -104,8 +101,8 @@ module Ci
end end
def ordered_by_last_commit_date def ordered_by_last_commit_date
last_commit_subquery = "(SELECT project_id, MAX(committed_at) committed_at FROM #{Ci::Commit.table_name} GROUP BY project_id)" last_commit_subquery = "(SELECT gl_project_id, MAX(committed_at) committed_at FROM #{Ci::Commit.table_name} GROUP BY gl_project_id)"
joins("LEFT JOIN #{last_commit_subquery} AS last_commit ON #{Ci::Project.table_name}.id = last_commit.project_id"). joins("LEFT JOIN #{last_commit_subquery} AS last_commit ON #{Ci::Project.table_name}.gitlab_id = last_commit.gl_project_id").
order("CASE WHEN last_commit.committed_at IS NULL THEN 1 ELSE 0 END, last_commit.committed_at DESC") order("CASE WHEN last_commit.committed_at IS NULL THEN 1 ELSE 0 END, last_commit.committed_at DESC")
end end
...@@ -125,10 +122,14 @@ module Ci ...@@ -125,10 +122,14 @@ module Ci
def set_default_values def set_default_values
self.token = SecureRandom.hex(15) if self.token.blank? self.token = SecureRandom.hex(15) if self.token.blank?
self.default_ref ||= 'master'
self.name ||= gl_project.name_with_namespace
self.path ||= gl_project.path_with_namespace
self.ssh_url_to_repo ||= gl_project.ssh_url_to_repo
end end
def tracked_refs def tracked_refs
@tracked_refs ||= default_ref.split(",").map{|ref| ref.strip} @tracked_refs ||= default_ref.split(",").map { |ref| ref.strip }
end end
def valid_token? token def valid_token? token
...@@ -207,5 +208,13 @@ module Ci ...@@ -207,5 +208,13 @@ module Ci
def setup_finished? def setup_finished?
commits.any? commits.any?
end end
def commits
gl_project.ci_commits
end
def builds
gl_project.ci_builds
end
end end
end end
...@@ -41,6 +41,10 @@ module Ci ...@@ -41,6 +41,10 @@ module Ci
query: "%#{query.try(:downcase)}%") query: "%#{query.try(:downcase)}%")
end end
def gl_projects_ids
projects.select(:gitlab_id)
end
def set_default_values def set_default_values
self.token = SecureRandom.hex(15) if self.token.blank? self.token = SecureRandom.hex(15) if self.token.blank?
end end
......
...@@ -118,6 +118,8 @@ class Project < ActiveRecord::Base ...@@ -118,6 +118,8 @@ class Project < ActiveRecord::Base
has_many :deploy_keys, through: :deploy_keys_projects has_many :deploy_keys, through: :deploy_keys_projects
has_many :users_star_projects, dependent: :destroy has_many :users_star_projects, dependent: :destroy
has_many :starrers, through: :users_star_projects, source: :user has_many :starrers, through: :users_star_projects, source: :user
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 :import_data, dependent: :destroy, class_name: "ProjectImportData"
has_one :gitlab_ci_project, dependent: :destroy, class_name: "Ci::Project", foreign_key: :gitlab_id has_one :gitlab_ci_project, dependent: :destroy, class_name: "Ci::Project", foreign_key: :gitlab_id
...@@ -745,6 +747,10 @@ class Project < ActiveRecord::Base ...@@ -745,6 +747,10 @@ class Project < ActiveRecord::Base
gitlab_ci_project.commits.find_by(sha: sha) if gitlab_ci? gitlab_ci_project.commits.find_by(sha: sha) if gitlab_ci?
end end
def ensure_gitlab_ci_project
gitlab_ci_project || create_gitlab_ci_project
end
def enable_ci(user) def enable_ci(user)
# Enable service # Enable service
service = gitlab_ci_service || create_gitlab_ci_service service = gitlab_ci_service || create_gitlab_ci_service
......
...@@ -8,10 +8,10 @@ module Ci ...@@ -8,10 +8,10 @@ module Ci
builds = builds =
if current_runner.shared? if current_runner.shared?
# don't run projects which have not enables shared runners # don't run projects which have not enables shared runners
builds.includes(:project).where(ci_projects: { shared_runners_enabled: true }) builds.joins(commit: { gl_project: :gitlab_ci_project }).where(ci_projects: { shared_runners_enabled: true })
else else
# do run projects which are only assigned to this runner # do run projects which are only assigned to this runner
builds.where(project_id: current_runner.projects) builds.joins(:commit).where(ci_commits: { gl_project_id: current_runner.gl_projects_ids })
end end
builds = builds.order('created_at ASC') builds = builds.order('created_at ASC')
......
- last_commit = project.last_commit - last_commit = project.commits.last
%tr %tr
%td %td
= project.id = project.id
......
class AddProjectIdToCiCommit < ActiveRecord::Migration
def up
add_column :ci_commits, :gl_project_id, :integer
end
end
class MigrateProjectIdForCiCommits < ActiveRecord::Migration
def up
subquery = 'SELECT gitlab_id FROM ci_projects WHERE ci_projects.id = ci_commits.project_id'
execute("UPDATE ci_commits SET gl_project_id=(#{subquery}) WHERE gl_project_id IS NULL")
end
end
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20150920161119) do ActiveRecord::Schema.define(version: 20150924125436) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
...@@ -118,6 +118,7 @@ ActiveRecord::Schema.define(version: 20150920161119) do ...@@ -118,6 +118,7 @@ ActiveRecord::Schema.define(version: 20150920161119) do
t.boolean "tag", default: false t.boolean "tag", default: false
t.text "yaml_errors" t.text "yaml_errors"
t.datetime "committed_at" t.datetime "committed_at"
t.integer "gl_project_id"
end end
add_index "ci_commits", ["project_id", "committed_at", "id"], name: "index_ci_commits_on_project_id_and_committed_at_and_id", using: :btree add_index "ci_commits", ["project_id", "committed_at", "id"], name: "index_ci_commits_on_project_id_and_committed_at_and_id", using: :btree
......
...@@ -104,7 +104,7 @@ class Spinach::Features::ProjectCommits < Spinach::FeatureSteps ...@@ -104,7 +104,7 @@ class Spinach::Features::ProjectCommits < Spinach::FeatureSteps
step 'commit has ci status' do step 'commit has ci status' do
@project.enable_ci(@user) @project.enable_ci(@user)
create :ci_commit, project: @project.gitlab_ci_project, sha: sample_commit.id create :ci_commit, gl_project: @project, sha: sample_commit.id
end end
step 'I see commit ci info' do step 'I see commit ci info' do
......
...@@ -204,6 +204,6 @@ module SharedProject ...@@ -204,6 +204,6 @@ module SharedProject
step 'project "Shop" has CI build' do step 'project "Shop" has CI build' do
project = Project.find_by(name: "Shop") project = Project.find_by(name: "Shop")
create :ci_commit, project: project.gitlab_ci_project, sha: project.commit.sha create :ci_commit, gl_project: project, sha: project.commit.sha
end end
end end
require "spec_helper" require "spec_helper"
describe Ci::CommitsController do describe Ci::CommitsController do
before do
@project = FactoryGirl.create :ci_project
end
describe "GET /status" do describe "GET /status" do
it "returns status of commit" do it "returns status of commit" do
commit = FactoryGirl.create :ci_commit, project: @project commit = FactoryGirl.create :ci_commit
get :status, id: commit.sha, ref_id: commit.ref, project_id: @project.id get :status, id: commit.sha, ref_id: commit.ref, project_id: commit.project.id
expect(response).to be_success expect(response).to be_success
expect(response.code).to eq('200') expect(response.code).to eq('200')
...@@ -16,8 +12,8 @@ describe Ci::CommitsController do ...@@ -16,8 +12,8 @@ describe Ci::CommitsController do
end end
it "returns not_found status" do it "returns not_found status" do
commit = FactoryGirl.create :ci_commit, project: @project commit = FactoryGirl.create :ci_commit
get :status, id: commit.sha, ref_id: "deploy", project_id: @project.id get :status, id: commit.sha, ref_id: "deploy", project_id: commit.project.id
expect(response).to be_success expect(response).to be_success
expect(response.code).to eq('200') expect(response.code).to eq('200')
......
...@@ -51,6 +51,8 @@ FactoryGirl.define do ...@@ -51,6 +51,8 @@ FactoryGirl.define do
} }
end end
gl_project factory: :empty_project
factory :ci_commit_without_jobs do factory :ci_commit_without_jobs do
after(:create) do |commit, evaluator| after(:create) do |commit, evaluator|
commit.push_data[:ci_yaml_file] = YAML.dump({}) commit.push_data[:ci_yaml_file] = YAML.dump({})
......
...@@ -43,7 +43,7 @@ FactoryGirl.define do ...@@ -43,7 +43,7 @@ FactoryGirl.define do
"git@demo.gitlab.com:gitlab/gitlab-shell#{n}.git" "git@demo.gitlab.com:gitlab/gitlab-shell#{n}.git"
end end
gl_project factory: :project gl_project factory: :empty_project
factory :ci_project do factory :ci_project do
token 'iPWx6WM4lhHNedGfBpPJNP' token 'iPWx6WM4lhHNedGfBpPJNP'
......
require 'spec_helper' require 'spec_helper'
describe "Admin Builds" do describe "Admin Builds" do
let(:project) { FactoryGirl.create :ci_project } let(:commit) { FactoryGirl.create :ci_commit }
let(:commit) { FactoryGirl.create :ci_commit, project: project }
let(:build) { FactoryGirl.create :ci_build, commit: commit } let(:build) { FactoryGirl.create :ci_build, commit: commit }
before do before do
......
...@@ -3,16 +3,15 @@ require 'spec_helper' ...@@ -3,16 +3,15 @@ require 'spec_helper'
describe "Builds" do describe "Builds" do
context :private_project do context :private_project do
before do before do
@project = FactoryGirl.create :ci_project @commit = FactoryGirl.create :ci_commit
@commit = FactoryGirl.create :ci_commit, project: @project
@build = FactoryGirl.create :ci_build, commit: @commit @build = FactoryGirl.create :ci_build, commit: @commit
login_as :user login_as :user
@project.gl_project.team << [@user, :master] @commit.project.gl_project.team << [@user, :master]
end end
describe "GET /:project/builds/:id" do describe "GET /:project/builds/:id" do
before do before do
visit ci_project_build_path(@project, @build) visit ci_project_build_path(@commit.project, @build)
end end
it { expect(page).to have_content @commit.sha[0..7] } it { expect(page).to have_content @commit.sha[0..7] }
...@@ -23,7 +22,7 @@ describe "Builds" do ...@@ -23,7 +22,7 @@ describe "Builds" do
describe "GET /:project/builds/:id/cancel" do describe "GET /:project/builds/:id/cancel" do
before do before do
@build.run! @build.run!
visit cancel_ci_project_build_path(@project, @build) visit cancel_ci_project_build_path(@commit.project, @build)
end end
it { expect(page).to have_content 'canceled' } it { expect(page).to have_content 'canceled' }
...@@ -33,7 +32,7 @@ describe "Builds" do ...@@ -33,7 +32,7 @@ describe "Builds" do
describe "POST /:project/builds/:id/retry" do describe "POST /:project/builds/:id/retry" do
before do before do
@build.cancel! @build.cancel!
visit ci_project_build_path(@project, @build) visit ci_project_build_path(@commit.project, @build)
click_link 'Retry' click_link 'Retry'
end end
...@@ -45,13 +44,15 @@ describe "Builds" do ...@@ -45,13 +44,15 @@ describe "Builds" do
context :public_project do context :public_project do
describe "Show page public accessible" do describe "Show page public accessible" do
before do before do
@project = FactoryGirl.create :ci_public_project @commit = FactoryGirl.create :ci_commit
@commit = FactoryGirl.create :ci_commit, project: @project @commit.project.public = true
@commit.project.save
@runner = FactoryGirl.create :ci_specific_runner @runner = FactoryGirl.create :ci_specific_runner
@build = FactoryGirl.create :ci_build, commit: @commit, runner: @runner @build = FactoryGirl.create :ci_build, commit: @commit, runner: @runner
stub_gitlab_calls stub_gitlab_calls
visit ci_project_build_path(@project, @build) visit ci_project_build_path(@commit.project, @build)
end end
it { expect(page).to have_content @commit.sha[0..7] } it { expect(page).to have_content @commit.sha[0..7] }
......
...@@ -5,11 +5,10 @@ describe "Commits" do ...@@ -5,11 +5,10 @@ describe "Commits" do
context "Authenticated user" do context "Authenticated user" do
before do before do
@project = FactoryGirl.create :ci_project @commit = FactoryGirl.create :ci_commit
@commit = FactoryGirl.create :ci_commit, project: @project
@build = FactoryGirl.create :ci_build, commit: @commit @build = FactoryGirl.create :ci_build, commit: @commit
login_as :user login_as :user
@project.gl_project.team << [@user, :master] @commit.project.gl_project.team << [@user, :master]
end end
describe "GET /:project/commits/:sha" do describe "GET /:project/commits/:sha" do
...@@ -51,8 +50,10 @@ describe "Commits" do ...@@ -51,8 +50,10 @@ describe "Commits" do
context "Public pages" do context "Public pages" do
before do before do
@project = FactoryGirl.create :ci_public_project @commit = FactoryGirl.create :ci_commit
@commit = FactoryGirl.create :ci_commit, project: @project @commit.project.public = true
@commit.project.save
@build = FactoryGirl.create :ci_build, commit: @commit @build = FactoryGirl.create :ci_build, commit: @commit
end end
......
...@@ -4,13 +4,12 @@ describe "Charts" do ...@@ -4,13 +4,12 @@ describe "Charts" do
context "build_times" do context "build_times" do
before do before do
@project = FactoryGirl.create(:ci_project) @commit = FactoryGirl.create(:ci_commit)
@commit = FactoryGirl.create(:ci_commit, project: @project)
FactoryGirl.create(:ci_build, commit: @commit) FactoryGirl.create(:ci_build, commit: @commit)
end end
it 'should return build times in minutes' do it 'should return build times in minutes' do
chart = Ci::Charts::BuildTime.new(@project) chart = Ci::Charts::BuildTime.new(@commit.project)
expect(chart.build_times).to eq([2]) expect(chart.build_times).to eq([2])
end end
end end
......
...@@ -5,8 +5,7 @@ describe Ci::Notify do ...@@ -5,8 +5,7 @@ describe Ci::Notify do
include EmailSpec::Matchers include EmailSpec::Matchers
before do before do
@project = FactoryGirl.create :ci_project @commit = FactoryGirl.create :ci_commit
@commit = FactoryGirl.create :ci_commit, project: @project
@build = FactoryGirl.create :ci_build, commit: @commit @build = FactoryGirl.create :ci_build, commit: @commit
end end
......
...@@ -27,7 +27,8 @@ require 'spec_helper' ...@@ -27,7 +27,8 @@ require 'spec_helper'
describe Ci::Build do describe Ci::Build do
let(:project) { FactoryGirl.create :ci_project } let(:project) { FactoryGirl.create :ci_project }
let(:commit) { FactoryGirl.create :ci_commit, project: project } let(:gl_project) { FactoryGirl.create :empty_project, gitlab_ci_project: project }
let(:commit) { FactoryGirl.create :ci_commit, gl_project: gl_project }
let(:build) { FactoryGirl.create :ci_build, commit: commit } let(:build) { FactoryGirl.create :ci_build, commit: commit }
it { is_expected.to belong_to(:commit) } it { is_expected.to belong_to(:commit) }
......
...@@ -19,11 +19,12 @@ require 'spec_helper' ...@@ -19,11 +19,12 @@ require 'spec_helper'
describe Ci::Commit do describe Ci::Commit do
let(:project) { FactoryGirl.create :ci_project } let(:project) { FactoryGirl.create :ci_project }
let(:commit) { FactoryGirl.create :ci_commit, project: project } let(:gl_project) { FactoryGirl.create :empty_project, gitlab_ci_project: project }
let(:commit_with_project) { FactoryGirl.create :ci_commit, project: project } let(:commit) { FactoryGirl.create :ci_commit, gl_project: gl_project }
let(:commit_with_project) { FactoryGirl.create :ci_commit, gl_project: gl_project }
let(:config_processor) { Ci::GitlabCiYamlProcessor.new(gitlab_ci_yaml) } let(:config_processor) { Ci::GitlabCiYamlProcessor.new(gitlab_ci_yaml) }
it { is_expected.to belong_to(:project) } it { is_expected.to belong_to(:gl_project) }
it { is_expected.to have_many(:builds) } it { is_expected.to have_many(:builds) }
it { is_expected.to validate_presence_of :before_sha } it { is_expected.to validate_presence_of :before_sha }
it { is_expected.to validate_presence_of :sha } it { is_expected.to validate_presence_of :sha }
...@@ -65,7 +66,8 @@ describe Ci::Commit do ...@@ -65,7 +66,8 @@ describe Ci::Commit do
project = FactoryGirl.create :ci_project, project = FactoryGirl.create :ci_project,
email_add_pusher: true, email_add_pusher: true,
email_recipients: '' email_recipients: ''
commit = FactoryGirl.create :ci_commit, project: project gl_project = FactoryGirl.create :empty_project, gitlab_ci_project: project
commit = FactoryGirl.create :ci_commit, gl_project: gl_project
expected = 'commit_pusher_email' expected = 'commit_pusher_email'
allow(commit).to receive(:push_data) { { user_email: expected } } allow(commit).to receive(:push_data) { { user_email: expected } }
expect(commit.project_recipients).to eq([expected]) expect(commit.project_recipients).to eq([expected])
...@@ -75,7 +77,8 @@ describe Ci::Commit do ...@@ -75,7 +77,8 @@ describe Ci::Commit do
project = FactoryGirl.create :ci_project, project = FactoryGirl.create :ci_project,
email_add_pusher: true, email_add_pusher: true,
email_recipients: 'rec1 rec2' email_recipients: 'rec1 rec2'
commit = FactoryGirl.create :ci_commit, project: project gl_project = FactoryGirl.create :empty_project, gitlab_ci_project: project
commit = FactoryGirl.create :ci_commit, gl_project: gl_project
expected = 'commit_pusher_email' expected = 'commit_pusher_email'
allow(commit).to receive(:push_data) { { user_email: expected } } allow(commit).to receive(:push_data) { { user_email: expected } }
expect(commit.project_recipients).to eq(['rec1', 'rec2', expected]) expect(commit.project_recipients).to eq(['rec1', 'rec2', expected])
...@@ -85,7 +88,8 @@ describe Ci::Commit do ...@@ -85,7 +88,8 @@ describe Ci::Commit do
project = FactoryGirl.create :ci_project, project = FactoryGirl.create :ci_project,
email_add_pusher: false, email_add_pusher: false,
email_recipients: 'rec1 rec2' email_recipients: 'rec1 rec2'
commit = FactoryGirl.create :ci_commit, project: project gl_project = FactoryGirl.create :empty_project, gitlab_ci_project: project
commit = FactoryGirl.create :ci_commit, gl_project: gl_project
expect(commit.project_recipients).to eq(['rec1', 'rec2']) expect(commit.project_recipients).to eq(['rec1', 'rec2'])
end end
...@@ -93,7 +97,8 @@ describe Ci::Commit do ...@@ -93,7 +97,8 @@ describe Ci::Commit do
project = FactoryGirl.create :ci_project, project = FactoryGirl.create :ci_project,
email_add_pusher: true, email_add_pusher: true,
email_recipients: 'rec1 rec1 rec2' email_recipients: 'rec1 rec1 rec2'
commit = FactoryGirl.create :ci_commit, project: project gl_project = FactoryGirl.create :empty_project, gitlab_ci_project: project
commit = FactoryGirl.create :ci_commit, gl_project: gl_project
expected = 'rec2' expected = 'rec2'
allow(commit).to receive(:push_data) { { user_email: expected } } allow(commit).to receive(:push_data) { { user_email: expected } }
expect(commit.project_recipients).to eq(['rec1', 'rec2']) expect(commit.project_recipients).to eq(['rec1', 'rec2'])
...@@ -219,8 +224,7 @@ describe Ci::Commit do ...@@ -219,8 +224,7 @@ describe Ci::Commit do
end end
describe "#finished_at" do describe "#finished_at" do
let(:project) { FactoryGirl.create :ci_project } let(:commit) { FactoryGirl.create :ci_commit }
let(:commit) { FactoryGirl.create :ci_commit, project: project }
it "returns finished_at of latest build" do it "returns finished_at of latest build" do
build = FactoryGirl.create :ci_build, commit: commit, finished_at: Time.now - 60 build = FactoryGirl.create :ci_build, commit: commit, finished_at: Time.now - 60
...@@ -238,7 +242,8 @@ describe Ci::Commit do ...@@ -238,7 +242,8 @@ describe Ci::Commit do
describe "coverage" do describe "coverage" do
let(:project) { FactoryGirl.create :ci_project, coverage_regex: "/.*/" } let(:project) { FactoryGirl.create :ci_project, coverage_regex: "/.*/" }
let(:commit) { FactoryGirl.create :ci_commit, project: project } let(:gl_project) { FactoryGirl.create :empty_project, gitlab_ci_project: project }
let(:commit) { FactoryGirl.create :ci_commit, gl_project: gl_project }
it "calculates average when there are two builds with coverage" do it "calculates average when there are two builds with coverage" do
FactoryGirl.create :ci_build, name: "rspec", coverage: 30, commit: commit FactoryGirl.create :ci_build, name: "rspec", coverage: 30, commit: commit
......
...@@ -32,7 +32,8 @@ describe Ci::MailService do ...@@ -32,7 +32,8 @@ describe Ci::MailService do
describe 'failed build' do describe 'failed build' do
let(:project) { FactoryGirl.create(:ci_project, email_add_pusher: true) } let(:project) { FactoryGirl.create(:ci_project, email_add_pusher: true) }
let(:commit) { FactoryGirl.create(:ci_commit, project: project) } let(:gl_project) { FactoryGirl.create(:empty_project, gitlab_ci_project: project) }
let(:commit) { FactoryGirl.create(:ci_commit, gl_project: gl_project) }
let(:build) { FactoryGirl.create(:ci_build, status: :failed, commit: commit) } let(:build) { FactoryGirl.create(:ci_build, status: :failed, commit: commit) }
before do before do
...@@ -54,7 +55,8 @@ describe Ci::MailService do ...@@ -54,7 +55,8 @@ describe Ci::MailService do
describe 'successfull build' do describe 'successfull build' do
let(:project) { FactoryGirl.create(:ci_project, email_add_pusher: true, email_only_broken_builds: false) } let(:project) { FactoryGirl.create(:ci_project, email_add_pusher: true, email_only_broken_builds: false) }
let(:commit) { FactoryGirl.create(:ci_commit, project: project) } let(:gl_project) { FactoryGirl.create(:empty_project, gitlab_ci_project: project) }
let(:commit) { FactoryGirl.create(:ci_commit, gl_project: gl_project) }
let(:build) { FactoryGirl.create(:ci_build, status: :success, commit: commit) } let(:build) { FactoryGirl.create(:ci_build, status: :success, commit: commit) }
before do before do
...@@ -81,7 +83,8 @@ describe Ci::MailService do ...@@ -81,7 +83,8 @@ describe Ci::MailService do
email_only_broken_builds: false, email_only_broken_builds: false,
email_recipients: "jeroen@example.com") email_recipients: "jeroen@example.com")
end end
let(:commit) { FactoryGirl.create(:ci_commit, project: project) } let(:gl_project) { FactoryGirl.create(:empty_project, gitlab_ci_project: project) }
let(:commit) { FactoryGirl.create(:ci_commit, gl_project: gl_project) }
let(:build) { FactoryGirl.create(:ci_build, status: :success, commit: commit) } let(:build) { FactoryGirl.create(:ci_build, status: :success, commit: commit) }
before do before do
...@@ -109,7 +112,8 @@ describe Ci::MailService do ...@@ -109,7 +112,8 @@ describe Ci::MailService do
email_only_broken_builds: true, email_only_broken_builds: true,
email_recipients: "jeroen@example.com") email_recipients: "jeroen@example.com")
end end
let(:commit) { FactoryGirl.create(:ci_commit, project: project) } let(:gl_project) { FactoryGirl.create(:empty_project, gitlab_ci_project: project) }
let(:commit) { FactoryGirl.create(:ci_commit, gl_project: gl_project) }
let(:build) { FactoryGirl.create(:ci_build, status: :success, commit: commit) } let(:build) { FactoryGirl.create(:ci_build, status: :success, commit: commit) }
before do before do
...@@ -137,7 +141,8 @@ describe Ci::MailService do ...@@ -137,7 +141,8 @@ describe Ci::MailService do
email_only_broken_builds: false, email_only_broken_builds: false,
email_recipients: "jeroen@example.com") email_recipients: "jeroen@example.com")
end end
let(:commit) { FactoryGirl.create(:ci_commit, project: project) } let(:gl_project) { FactoryGirl.create(:empty_project, gitlab_ci_project: project) }
let(:commit) { FactoryGirl.create(:ci_commit, gl_project: gl_project) }
let(:build) { FactoryGirl.create(:ci_build, status: :success, commit: commit) } let(:build) { FactoryGirl.create(:ci_build, status: :success, commit: commit) }
before do before do
...@@ -159,7 +164,8 @@ describe Ci::MailService do ...@@ -159,7 +164,8 @@ describe Ci::MailService do
email_only_broken_builds: true, email_only_broken_builds: true,
email_recipients: "jeroen@example.com") email_recipients: "jeroen@example.com")
end end
let(:commit) { FactoryGirl.create(:ci_commit, project: project) } let(:gl_project) { FactoryGirl.create(:empty_project, gitlab_ci_project: project) }
let(:commit) { FactoryGirl.create(:ci_commit, gl_project: gl_project) }
let(:build) { FactoryGirl.create(:ci_build, status: :failed, commit: commit) } let(:build) { FactoryGirl.create(:ci_build, status: :failed, commit: commit) }
before do before do
......
...@@ -3,10 +3,8 @@ require 'spec_helper' ...@@ -3,10 +3,8 @@ require 'spec_helper'
describe Ci::HipChatMessage do describe Ci::HipChatMessage do
subject { Ci::HipChatMessage.new(build) } subject { Ci::HipChatMessage.new(build) }
let(:project) { FactoryGirl.create(:ci_project) }
context "One build" do context "One build" do
let(:commit) { FactoryGirl.create(:ci_commit_with_one_job, project: project) } let(:commit) { FactoryGirl.create(:ci_commit_with_one_job) }
let(:build) do let(:build) do
commit.create_builds commit.create_builds
...@@ -37,7 +35,7 @@ describe Ci::HipChatMessage do ...@@ -37,7 +35,7 @@ describe Ci::HipChatMessage do
end end
context "Several builds" do context "Several builds" do
let(:commit) { FactoryGirl.create(:ci_commit_with_two_jobs, project: project) } let(:commit) { FactoryGirl.create(:ci_commit_with_two_jobs) }
let(:build) do let(:build) do
commit.builds.first commit.builds.first
......
...@@ -33,15 +33,14 @@ describe Ci::HipChatService do ...@@ -33,15 +33,14 @@ describe Ci::HipChatService do
describe "Execute" do describe "Execute" do
let(:service) { Ci::HipChatService.new } let(:service) { Ci::HipChatService.new }
let(:project) { FactoryGirl.create :ci_project } let(:commit) { FactoryGirl.create :ci_commit }
let(:commit) { FactoryGirl.create :ci_commit, project: project }
let(:build) { FactoryGirl.create :ci_build, commit: commit, status: 'failed' } let(:build) { FactoryGirl.create :ci_build, commit: commit, status: 'failed' }
let(:api_url) { 'https://api.hipchat.com/v2/room/123/notification?auth_token=a1b2c3d4e5f6' } let(:api_url) { 'https://api.hipchat.com/v2/room/123/notification?auth_token=a1b2c3d4e5f6' }
before do before do
allow(service).to receive_messages( allow(service).to receive_messages(
project: project, project: commit.project,
project_id: project.id, project_id: commit.project_id,
notify_only_broken_builds: false, notify_only_broken_builds: false,
hipchat_room: 123, hipchat_room: 123,
hipchat_token: 'a1b2c3d4e5f6' hipchat_token: 'a1b2c3d4e5f6'
......
...@@ -3,10 +3,8 @@ require 'spec_helper' ...@@ -3,10 +3,8 @@ require 'spec_helper'
describe Ci::SlackMessage do describe Ci::SlackMessage do
subject { Ci::SlackMessage.new(commit) } subject { Ci::SlackMessage.new(commit) }
let(:project) { FactoryGirl.create :ci_project }
context "One build" do context "One build" do
let(:commit) { FactoryGirl.create(:ci_commit_with_one_job, project: project) } let(:commit) { FactoryGirl.create(:ci_commit_with_one_job) }
let(:build) do let(:build) do
commit.create_builds commit.create_builds
...@@ -43,7 +41,7 @@ describe Ci::SlackMessage do ...@@ -43,7 +41,7 @@ describe Ci::SlackMessage do
end end
context "Several builds" do context "Several builds" do
let(:commit) { FactoryGirl.create(:ci_commit_with_two_jobs, project: project) } let(:commit) { FactoryGirl.create(:ci_commit_with_two_jobs) }
context 'when all matrix builds succeeded' do context 'when all matrix builds succeeded' do
let(:color) { 'good' } let(:color) { 'good' }
......
...@@ -31,16 +31,15 @@ describe Ci::SlackService do ...@@ -31,16 +31,15 @@ describe Ci::SlackService do
describe "Execute" do describe "Execute" do
let(:slack) { Ci::SlackService.new } let(:slack) { Ci::SlackService.new }
let(:project) { FactoryGirl.create :ci_project } let(:commit) { FactoryGirl.create :ci_commit }
let(:commit) { FactoryGirl.create :ci_commit, project: project }
let(:build) { FactoryGirl.create :ci_build, commit: commit, status: 'failed' } let(:build) { FactoryGirl.create :ci_build, commit: commit, status: 'failed' }
let(:webhook_url) { 'https://hooks.slack.com/services/SVRWFV0VVAR97N/B02R25XN3/ZBqu7xMupaEEICInN685' } let(:webhook_url) { 'https://hooks.slack.com/services/SVRWFV0VVAR97N/B02R25XN3/ZBqu7xMupaEEICInN685' }
let(:notify_only_broken_builds) { false } let(:notify_only_broken_builds) { false }
before do before do
allow(slack).to receive_messages( allow(slack).to receive_messages(
project: project, project: commit.project,
project_id: project.id, project_id: commit.project_id,
webhook: webhook_url, webhook: webhook_url,
notify_only_broken_builds: notify_only_broken_builds notify_only_broken_builds: notify_only_broken_builds
) )
......
...@@ -28,13 +28,18 @@ ...@@ -28,13 +28,18 @@
require 'spec_helper' require 'spec_helper'
describe Ci::Project do describe Ci::Project do
subject { FactoryGirl.build :ci_project } let(:gl_project) { FactoryGirl.create :empty_project }
subject { FactoryGirl.create :ci_project, gl_project: gl_project }
it { is_expected.to have_many(:commits) } it { is_expected.to have_many(:runner_projects) }
it { is_expected.to have_many(:runners) }
it { is_expected.to have_many(:web_hooks) }
it { is_expected.to have_many(:events) }
it { is_expected.to have_many(:variables) }
it { is_expected.to have_many(:triggers) }
it { is_expected.to have_many(:services) }
it { is_expected.to validate_presence_of :name }
it { is_expected.to validate_presence_of :timeout } it { is_expected.to validate_presence_of :timeout }
it { is_expected.to validate_presence_of :default_ref }
describe 'before_validation' do describe 'before_validation' do
it 'should set an random token if none provided' do it 'should set an random token if none provided' do
...@@ -50,41 +55,45 @@ describe Ci::Project do ...@@ -50,41 +55,45 @@ describe Ci::Project do
describe "ordered_by_last_commit_date" do describe "ordered_by_last_commit_date" do
it "returns ordered projects" do it "returns ordered projects" do
newest_project = FactoryGirl.create :ci_project newest_project = FactoryGirl.create :empty_project
oldest_project = FactoryGirl.create :ci_project newest_ci_project = newest_project.ensure_gitlab_ci_project
project_without_commits = FactoryGirl.create :ci_project oldest_project = FactoryGirl.create :empty_project
oldest_ci_project = oldest_project.ensure_gitlab_ci_project
project_without_commits = FactoryGirl.create :empty_project
ci_project_without_commits = project_without_commits.ensure_gitlab_ci_project
FactoryGirl.create :ci_commit, committed_at: 1.hour.ago, project: newest_project FactoryGirl.create :ci_commit, committed_at: 1.hour.ago, gl_project: newest_project
FactoryGirl.create :ci_commit, committed_at: 2.hour.ago, project: oldest_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, oldest_project, project_without_commits]) expect(Ci::Project.ordered_by_last_commit_date).to eq([newest_ci_project, oldest_ci_project, ci_project_without_commits])
end end
end end
describe 'ordered commits' do describe 'ordered commits' do
let(:project) { FactoryGirl.create :ci_project } let(:project) { FactoryGirl.create :empty_project }
it 'returns ordered list of commits' do it 'returns ordered list of commits' do
commit1 = FactoryGirl.create :ci_commit, committed_at: 1.hour.ago, project: project commit1 = FactoryGirl.create :ci_commit, committed_at: 1.hour.ago, gl_project: project
commit2 = FactoryGirl.create :ci_commit, committed_at: 2.hour.ago, 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 end
it 'returns commits ordered by committed_at and id, with nulls last' do it 'returns commits ordered by committed_at and id, with nulls last' do
commit1 = FactoryGirl.create :ci_commit, committed_at: 1.hour.ago, project: project commit1 = FactoryGirl.create :ci_commit, committed_at: 1.hour.ago, gl_project: project
commit2 = FactoryGirl.create :ci_commit, committed_at: nil, project: project commit2 = FactoryGirl.create :ci_commit, committed_at: nil, gl_project: project
commit3 = FactoryGirl.create :ci_commit, committed_at: 2.hour.ago, project: project commit3 = FactoryGirl.create :ci_commit, committed_at: 2.hour.ago, gl_project: project
commit4 = FactoryGirl.create :ci_commit, committed_at: nil, 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
end end
context :valid_project do context :valid_project do
let(:project) { FactoryGirl.create :ci_project } let(:commit) { FactoryGirl.create(:ci_commit) }
context :project_with_commit_and_builds do context :project_with_commit_and_builds do
let(:project) { commit.project }
before do before do
commit = FactoryGirl.create(:ci_commit, project: project)
FactoryGirl.create(:ci_build, commit: commit) FactoryGirl.create(:ci_build, commit: commit)
end end
......
...@@ -29,13 +29,12 @@ describe Ci::Service do ...@@ -29,13 +29,12 @@ describe Ci::Service do
end end
describe "Testable" do describe "Testable" do
let(:project) { FactoryGirl.create :ci_project } let(:commit) { FactoryGirl.create :ci_commit }
let(:commit) { FactoryGirl.create :ci_commit, project: project }
let(:build) { FactoryGirl.create :ci_build, commit: commit } let(:build) { FactoryGirl.create :ci_build, commit: commit }
before do before do
allow(@service).to receive_messages( allow(@service).to receive_messages(
project: project project: commit.project
) )
build build
@testable = @service.can_test? @testable = @service.can_test?
......
...@@ -404,10 +404,12 @@ describe Project do ...@@ -404,10 +404,12 @@ describe Project do
describe :ci_commit do describe :ci_commit do
let(:project) { create :project } let(:project) { create :project }
let(:ci_project) { create :ci_project, gl_project: project } let(:commit) { create :ci_commit, gl_project: project }
let(:commit) { create :ci_commit, project: ci_project }
before { project.create_gitlab_ci_service(active: true) } before do
project.ensure_gitlab_ci_project
project.create_gitlab_ci_service(active: true)
end
it { expect(project.ci_commit(commit.sha)).to eq(commit) } it { expect(project.ci_commit(commit.sha)).to eq(commit) }
end end
......
...@@ -5,10 +5,12 @@ describe Ci::API::API do ...@@ -5,10 +5,12 @@ describe Ci::API::API do
let(:runner) { FactoryGirl.create(:ci_runner, tag_list: ["mysql", "ruby"]) } let(:runner) { FactoryGirl.create(:ci_runner, tag_list: ["mysql", "ruby"]) }
let(:project) { FactoryGirl.create(:ci_project) } let(:project) { FactoryGirl.create(:ci_project) }
let(:gl_project) { FactoryGirl.create(:empty_project, gitlab_ci_project: project) }
describe "Builds API for runners" do describe "Builds API for runners" do
let(:shared_runner) { FactoryGirl.create(:ci_runner, token: "SharedRunner") } let(:shared_runner) { FactoryGirl.create(:ci_runner, token: "SharedRunner") }
let(:shared_project) { FactoryGirl.create(:ci_project, name: "SharedProject") } let(:shared_project) { FactoryGirl.create(:ci_project, name: "SharedProject") }
let(:shared_gl_project) { FactoryGirl.create(:empty_project, gitlab_ci_project: shared_project) }
before do before do
FactoryGirl.create :ci_runner_project, project_id: project.id, runner_id: runner.id FactoryGirl.create :ci_runner_project, project_id: project.id, runner_id: runner.id
...@@ -16,7 +18,7 @@ describe Ci::API::API do ...@@ -16,7 +18,7 @@ describe Ci::API::API do
describe "POST /builds/register" do describe "POST /builds/register" do
it "should start a build" do it "should start a build" do
commit = FactoryGirl.create(:ci_commit, project: project) commit = FactoryGirl.create(:ci_commit, gl_project: gl_project)
commit.create_builds commit.create_builds
build = commit.builds.first build = commit.builds.first
...@@ -34,7 +36,7 @@ describe Ci::API::API do ...@@ -34,7 +36,7 @@ describe Ci::API::API do
end end
it "should return 404 error if no builds for specific runner" do it "should return 404 error if no builds for specific runner" do
commit = FactoryGirl.create(:ci_commit, project: shared_project) commit = FactoryGirl.create(:ci_commit, gl_project: shared_gl_project)
FactoryGirl.create(:ci_build, commit: commit, status: 'pending' ) FactoryGirl.create(:ci_build, commit: commit, status: 'pending' )
post ci_api("/builds/register"), token: runner.token post ci_api("/builds/register"), token: runner.token
...@@ -43,7 +45,7 @@ describe Ci::API::API do ...@@ -43,7 +45,7 @@ describe Ci::API::API do
end end
it "should return 404 error if no builds for shared runner" do it "should return 404 error if no builds for shared runner" do
commit = FactoryGirl.create(:ci_commit, project: project) commit = FactoryGirl.create(:ci_commit, gl_project: gl_project)
FactoryGirl.create(:ci_build, commit: commit, status: 'pending' ) FactoryGirl.create(:ci_build, commit: commit, status: 'pending' )
post ci_api("/builds/register"), token: shared_runner.token post ci_api("/builds/register"), token: shared_runner.token
...@@ -52,7 +54,7 @@ describe Ci::API::API do ...@@ -52,7 +54,7 @@ describe Ci::API::API do
end end
it "returns options" do it "returns options" do
commit = FactoryGirl.create(:ci_commit, project: project) commit = FactoryGirl.create(:ci_commit, gl_project: gl_project)
commit.create_builds commit.create_builds
post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin } post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin }
...@@ -62,7 +64,7 @@ describe Ci::API::API do ...@@ -62,7 +64,7 @@ describe Ci::API::API do
end end
it "returns variables" do it "returns variables" do
commit = FactoryGirl.create(:ci_commit, project: project) commit = FactoryGirl.create(:ci_commit, gl_project: gl_project)
commit.create_builds commit.create_builds
project.variables << Ci::Variable.new(key: "SECRET_KEY", value: "secret_value") project.variables << Ci::Variable.new(key: "SECRET_KEY", value: "secret_value")
...@@ -77,7 +79,7 @@ describe Ci::API::API do ...@@ -77,7 +79,7 @@ describe Ci::API::API do
it "returns variables for triggers" do it "returns variables for triggers" do
trigger = FactoryGirl.create(:ci_trigger, project: project) trigger = FactoryGirl.create(:ci_trigger, project: project)
commit = FactoryGirl.create(:ci_commit, project: project) commit = FactoryGirl.create(:ci_commit, gl_project: gl_project)
trigger_request = FactoryGirl.create(:ci_trigger_request_with_variables, commit: commit, trigger: trigger) trigger_request = FactoryGirl.create(:ci_trigger_request_with_variables, commit: commit, trigger: trigger)
commit.create_builds(trigger_request) commit.create_builds(trigger_request)
...@@ -95,7 +97,7 @@ describe Ci::API::API do ...@@ -95,7 +97,7 @@ describe Ci::API::API do
end end
describe "PUT /builds/:id" do describe "PUT /builds/:id" do
let(:commit) { FactoryGirl.create(:ci_commit, project: project)} let(:commit) { FactoryGirl.create(:ci_commit, gl_project: gl_project)}
let(:build) { FactoryGirl.create(:ci_build, commit: commit, runner_id: runner.id) } let(:build) { FactoryGirl.create(:ci_build, commit: commit, runner_id: runner.id) }
it "should update a running build" do it "should update a running build" do
......
...@@ -4,7 +4,8 @@ describe Ci::API::API, 'Commits' do ...@@ -4,7 +4,8 @@ describe Ci::API::API, 'Commits' do
include ApiHelpers include ApiHelpers
let(:project) { FactoryGirl.create(:ci_project) } let(:project) { FactoryGirl.create(:ci_project) }
let(:commit) { FactoryGirl.create(:ci_commit, project: project) } let(:gl_project) { FactoryGirl.create(:empty_project, gitlab_ci_project: project) }
let(:commit) { FactoryGirl.create(:ci_commit, gl_project: gl_project) }
let(:options) do let(:options) do
{ {
......
...@@ -6,6 +6,7 @@ describe Ci::API::API do ...@@ -6,6 +6,7 @@ describe Ci::API::API do
describe 'POST /projects/:project_id/refs/:ref/trigger' do describe 'POST /projects/:project_id/refs/:ref/trigger' do
let!(:trigger_token) { 'secure token' } let!(:trigger_token) { 'secure token' }
let!(:project) { FactoryGirl.create(:ci_project) } let!(:project) { FactoryGirl.create(:ci_project) }
let!(:gl_project) { FactoryGirl.create(:empty_project, gitlab_ci_project: project) }
let!(:project2) { FactoryGirl.create(:ci_project) } let!(:project2) { FactoryGirl.create(:ci_project) }
let!(:trigger) { FactoryGirl.create(:ci_trigger, project: project, token: trigger_token) } let!(:trigger) { FactoryGirl.create(:ci_trigger, project: project, token: trigger_token) }
let(:options) do let(:options) do
...@@ -33,7 +34,7 @@ describe Ci::API::API do ...@@ -33,7 +34,7 @@ describe Ci::API::API do
context 'Have a commit' do context 'Have a commit' do
before do before do
@commit = FactoryGirl.create(:ci_commit, project: project) @commit = FactoryGirl.create(:ci_commit, gl_project: gl_project)
end end
it 'should create builds' do it 'should create builds' do
......
...@@ -2,14 +2,13 @@ require 'spec_helper' ...@@ -2,14 +2,13 @@ require 'spec_helper'
describe "Builds" do describe "Builds" do
before do before do
@project = FactoryGirl.create :ci_project @commit = FactoryGirl.create :ci_commit
@commit = FactoryGirl.create :ci_commit, project: @project
@build = FactoryGirl.create :ci_build, commit: @commit @build = FactoryGirl.create :ci_build, commit: @commit
end end
describe "GET /:project/builds/:id/status.json" do describe "GET /:project/builds/:id/status.json" do
before do before do
get status_ci_project_build_path(@project, @build), format: :json get status_ci_project_build_path(@commit.project, @build), format: :json
end end
it { expect(response.status).to eq(200) } it { expect(response.status).to eq(200) }
......
...@@ -2,13 +2,12 @@ require 'spec_helper' ...@@ -2,13 +2,12 @@ require 'spec_helper'
describe "Commits" do describe "Commits" do
before do before do
@project = FactoryGirl.create :ci_project @commit = FactoryGirl.create :ci_commit
@commit = FactoryGirl.create :ci_commit, project: @project
end end
describe "GET /:project/refs/:ref_name/commits/:id/status.json" do describe "GET /:project/refs/:ref_name/commits/:id/status.json" do
before do before do
get status_ci_project_ref_commits_path(@project, @commit.ref, @commit.sha), format: :json get status_ci_project_ref_commits_path(@commit.project, @commit.ref, @commit.sha), format: :json
end end
it { expect(response.status).to eq(200) } it { expect(response.status).to eq(200) }
......
...@@ -3,6 +3,7 @@ require 'spec_helper' ...@@ -3,6 +3,7 @@ require 'spec_helper'
describe Ci::CreateTriggerRequestService do describe Ci::CreateTriggerRequestService do
let(:service) { Ci::CreateTriggerRequestService.new } let(:service) { Ci::CreateTriggerRequestService.new }
let(:project) { FactoryGirl.create :ci_project } let(:project) { FactoryGirl.create :ci_project }
let(:gl_project) { FactoryGirl.create :empty_project, gitlab_ci_project: project }
let(:trigger) { FactoryGirl.create :ci_trigger, project: project } let(:trigger) { FactoryGirl.create :ci_trigger, project: project }
describe :execute do describe :execute do
...@@ -10,7 +11,7 @@ describe Ci::CreateTriggerRequestService do ...@@ -10,7 +11,7 @@ describe Ci::CreateTriggerRequestService do
subject { service.execute(project, trigger, 'master') } subject { service.execute(project, trigger, 'master') }
before do before do
@commit = FactoryGirl.create :ci_commit, project: project @commit = FactoryGirl.create :ci_commit, gl_project: gl_project
end end
it { expect(subject).to be_kind_of(Ci::TriggerRequest) } it { expect(subject).to be_kind_of(Ci::TriggerRequest) }
...@@ -27,7 +28,7 @@ describe Ci::CreateTriggerRequestService do ...@@ -27,7 +28,7 @@ describe Ci::CreateTriggerRequestService do
subject { service.execute(project, trigger, 'master') } subject { service.execute(project, trigger, 'master') }
before do before do
FactoryGirl.create :ci_commit_without_jobs, project: project FactoryGirl.create :ci_commit_without_jobs, gl_project: gl_project
end end
it { expect(subject).to be_nil } it { expect(subject).to be_nil }
...@@ -37,9 +38,9 @@ describe Ci::CreateTriggerRequestService do ...@@ -37,9 +38,9 @@ describe Ci::CreateTriggerRequestService do
subject { service.execute(project, trigger, 'master') } subject { service.execute(project, trigger, 'master') }
before do before do
@commit1 = FactoryGirl.create :ci_commit, committed_at: 2.hour.ago, project: project @commit1 = FactoryGirl.create :ci_commit, committed_at: 2.hour.ago, gl_project: gl_project
@commit2 = FactoryGirl.create :ci_commit, committed_at: 1.hour.ago, project: project @commit2 = FactoryGirl.create :ci_commit, committed_at: 1.hour.ago, gl_project: gl_project
@commit3 = FactoryGirl.create :ci_commit, committed_at: 3.hour.ago, project: project @commit3 = FactoryGirl.create :ci_commit, committed_at: 3.hour.ago, gl_project: gl_project
end end
context 'retries latest one' do context 'retries latest one' do
......
...@@ -4,7 +4,8 @@ module Ci ...@@ -4,7 +4,8 @@ module Ci
describe ImageForBuildService do describe ImageForBuildService do
let(:service) { ImageForBuildService.new } let(:service) { ImageForBuildService.new }
let(:project) { FactoryGirl.create(:ci_project) } let(:project) { FactoryGirl.create(:ci_project) }
let(:commit) { FactoryGirl.create(:ci_commit, project: project, ref: 'master') } let(:gl_project) { FactoryGirl.create(:empty_project, gitlab_ci_project: project) }
let(:commit) { FactoryGirl.create(:ci_commit, gl_project: gl_project, ref: 'master') }
let(:build) { FactoryGirl.create(:ci_build, commit: commit) } let(:build) { FactoryGirl.create(:ci_build, commit: commit) }
describe :execute do describe :execute do
......
...@@ -3,14 +3,14 @@ require 'spec_helper' ...@@ -3,14 +3,14 @@ require 'spec_helper'
module Ci module Ci
describe RegisterBuildService do describe RegisterBuildService do
let!(:service) { RegisterBuildService.new } let!(:service) { RegisterBuildService.new }
let!(:project) { FactoryGirl.create :ci_project } let!(:gl_project) { FactoryGirl.create :empty_project }
let!(:commit) { FactoryGirl.create :ci_commit, project: project } let!(:commit) { FactoryGirl.create :ci_commit, gl_project: gl_project }
let!(:pending_build) { FactoryGirl.create :ci_build, project: project, commit: commit } let!(:pending_build) { FactoryGirl.create :ci_build, commit: commit }
let!(:shared_runner) { FactoryGirl.create(:ci_runner, is_shared: true) } let!(:shared_runner) { FactoryGirl.create(:ci_runner, is_shared: true) }
let!(:specific_runner) { FactoryGirl.create(:ci_runner, is_shared: false) } let!(:specific_runner) { FactoryGirl.create(:ci_runner, is_shared: false) }
before do before do
specific_runner.assign_to(project) specific_runner.assign_to(gl_project.ensure_gitlab_ci_project)
end end
describe :execute do describe :execute do
...@@ -47,8 +47,7 @@ module Ci ...@@ -47,8 +47,7 @@ module Ci
context 'allow shared runners' do context 'allow shared runners' do
before do before do
project.shared_runners_enabled = true gl_project.gitlab_ci_project.update(shared_runners_enabled: true)
project.save
end end
context 'shared runner' do context 'shared runner' do
......
...@@ -2,7 +2,8 @@ require 'spec_helper' ...@@ -2,7 +2,8 @@ require 'spec_helper'
describe Ci::WebHookService do describe Ci::WebHookService do
let(:project) { FactoryGirl.create :ci_project } let(:project) { FactoryGirl.create :ci_project }
let(:commit) { FactoryGirl.create :ci_commit, project: project } let(:gl_project) { FactoryGirl.create :empty_project, gitlab_ci_project: project }
let(:commit) { FactoryGirl.create :ci_commit, gl_project: gl_project }
let(:build) { FactoryGirl.create :ci_build, commit: commit } let(:build) { FactoryGirl.create :ci_build, commit: commit }
let(:hook) { FactoryGirl.create :ci_web_hook, project: project } let(:hook) { FactoryGirl.create :ci_web_hook, project: project }
......
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