diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2015-12-04 12:55:23 +0100 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2015-12-11 18:02:09 +0100 |
commit | e80e3f5372d6bcad1fbe04a85b3086bb66794828 (patch) | |
tree | 16b1539cfd158ecac7fe05d595cbba30b8bc1a04 /spec | |
parent | 8b4cdc50fca816b4f56f8579e17c4dba836ec797 (diff) | |
download | gitlab-ce-e80e3f5372d6bcad1fbe04a85b3086bb66794828.tar.gz |
Migrate CI::Project to Project
Diffstat (limited to 'spec')
38 files changed, 253 insertions, 961 deletions
diff --git a/spec/factories/ci/builds.rb b/spec/factories/ci/builds.rb index 2fcd70182b9..f76e826f138 100644 --- a/spec/factories/ci/builds.rb +++ b/spec/factories/ci/builds.rb @@ -42,6 +42,10 @@ FactoryGirl.define do commit factory: :ci_commit + after(:build) do |build, evaluator| + build.project = build.commit.project + end + factory :ci_not_started_build do started_at nil finished_at nil diff --git a/spec/factories/ci/commits.rb b/spec/factories/ci/commits.rb index 70e3fa319c6..b42cafa518a 100644 --- a/spec/factories/ci/commits.rb +++ b/spec/factories/ci/commits.rb @@ -21,7 +21,7 @@ FactoryGirl.define do factory :ci_empty_commit, class: Ci::Commit do sha '97de212e80737a608d939f648d959671fb0a0142' - gl_project factory: :empty_project + project factory: :empty_project factory :ci_commit_without_jobs do after(:build) do |commit| diff --git a/spec/factories/ci/events.rb b/spec/factories/ci/events.rb deleted file mode 100644 index 9638618a400..00000000000 --- a/spec/factories/ci/events.rb +++ /dev/null @@ -1,24 +0,0 @@ -# == Schema Information -# -# Table name: events -# -# id :integer not null, primary key -# project_id :integer -# user_id :integer -# is_admin :integer -# description :text -# created_at :datetime -# updated_at :datetime -# - -FactoryGirl.define do - factory :ci_event, class: Ci::Event do - sequence :description do |n| - "updated project settings#{n}" - end - - factory :ci_admin_event do - is_admin true - end - end -end diff --git a/spec/factories/ci/projects.rb b/spec/factories/ci/projects.rb deleted file mode 100644 index 11cb8c9eeaa..00000000000 --- a/spec/factories/ci/projects.rb +++ /dev/null @@ -1,50 +0,0 @@ -# == Schema Information -# -# Table name: projects -# -# id :integer not null, primary key -# name :string(255) not null -# timeout :integer default(3600), not null -# created_at :datetime -# updated_at :datetime -# token :string(255) -# default_ref :string(255) -# path :string(255) -# always_build :boolean default(FALSE), not null -# polling_interval :integer -# public :boolean default(FALSE), not null -# ssh_url_to_repo :string(255) -# gitlab_id :integer -# allow_git_fetch :boolean default(TRUE), not null -# email_recipients :string(255) default(""), not null -# email_add_pusher :boolean default(TRUE), not null -# email_only_broken_builds :boolean default(TRUE), not null -# skip_refs :string(255) -# coverage_regex :string(255) -# shared_runners_enabled :boolean default(FALSE) -# generated_yaml_config :text -# - -# Read about factories at https://github.com/thoughtbot/factory_girl - -FactoryGirl.define do - factory :ci_project_without_token, class: Ci::Project do - default_ref 'master' - - shared_runners_enabled false - - factory :ci_project do - token 'iPWx6WM4lhHNedGfBpPJNP' - end - - initialize_with do - # TODO: - # this is required, because builds_enabled is initialized when Project is created - # and this create gitlab_ci_project if builds is set to true - # here we take created gitlab_ci_project and update it's attributes - ci_project = create(:empty_project).ensure_gitlab_ci_project - ci_project.update_attributes(attributes) - ci_project - end - end -end diff --git a/spec/factories/ci/runner_projects.rb b/spec/factories/ci/runner_projects.rb index 3aa14ca434d..008d1c5d961 100644 --- a/spec/factories/ci/runner_projects.rb +++ b/spec/factories/ci/runner_projects.rb @@ -14,6 +14,6 @@ FactoryGirl.define do factory :ci_runner_project, class: Ci::RunnerProject do runner_id 1 - project_id 1 + gl_project_id 1 end end diff --git a/spec/features/ci/admin/builds_spec.rb b/spec/features/atom/builds_spec.rb index 623d466c67b..72764b1629d 100644 --- a/spec/features/ci/admin/builds_spec.rb +++ b/spec/features/atom/builds_spec.rb @@ -5,17 +5,16 @@ describe "Admin Builds" do let(:build) { FactoryGirl.create :ci_build, commit: commit } before do - skip_ci_admin_auth - login_as :user + login_as :admin end describe "GET /admin/builds" do before do build - visit ci_admin_builds_path + visit admin_builds_path end - it { expect(page).to have_content "All builds" } + it { expect(page).to have_content "Running" } it { expect(page).to have_content build.short_sha } end @@ -26,43 +25,43 @@ describe "Admin Builds" do FactoryGirl.create :ci_build, commit: commit, status: "success" FactoryGirl.create :ci_build, commit: commit, status: "failed" - visit ci_admin_builds_path + visit admin_builds_path + + within ".center-top-menu" do + click_on "All" + end expect(page.all(".build-link").size).to eq(4) end - it "shows pending builds" do + it "shows finished builds" do build = FactoryGirl.create :ci_build, commit: commit, status: "pending" build1 = FactoryGirl.create :ci_build, commit: commit, status: "running" build2 = FactoryGirl.create :ci_build, commit: commit, status: "success" - build3 = FactoryGirl.create :ci_build, commit: commit, status: "failed" - visit ci_admin_builds_path + visit admin_builds_path - within ".nav.nav-tabs" do - click_on "Pending" + within ".center-top-menu" do + click_on "Finished" end - expect(page.find(".build-link")).to have_content(build.id) + expect(page.find(".build-link")).not_to have_content(build.id) expect(page.find(".build-link")).not_to have_content(build1.id) - expect(page.find(".build-link")).not_to have_content(build2.id) - expect(page.find(".build-link")).not_to have_content(build3.id) + expect(page.find(".build-link")).to have_content(build2.id) end it "shows running builds" do build = FactoryGirl.create :ci_build, commit: commit, status: "pending" - build1 = FactoryGirl.create :ci_build, commit: commit, status: "running" build2 = FactoryGirl.create :ci_build, commit: commit, status: "success" build3 = FactoryGirl.create :ci_build, commit: commit, status: "failed" - visit ci_admin_builds_path + visit admin_builds_path - within ".nav.nav-tabs" do + within ".center-top-menu" do click_on "Running" end - expect(page.find(".build-link")).to have_content(build1.id) - expect(page.find(".build-link")).not_to have_content(build.id) + expect(page.find(".build-link")).to have_content(build.id) expect(page.find(".build-link")).not_to have_content(build2.id) expect(page.find(".build-link")).not_to have_content(build3.id) end diff --git a/spec/features/ci/admin/runners_spec.rb b/spec/features/atom/runners_spec.rb index b83744f53a8..b1f2d401042 100644 --- a/spec/features/ci/admin/runners_spec.rb +++ b/spec/features/atom/runners_spec.rb @@ -10,7 +10,7 @@ describe "Admin Runners" do runner = FactoryGirl.create(:ci_runner) commit = FactoryGirl.create(:ci_commit) FactoryGirl.create(:ci_build, commit: commit, runner_id: runner.id) - visit ci_admin_runners_path + visit admin_runners_path end it { page.has_text? "Manage Runners" } @@ -36,9 +36,9 @@ describe "Admin Runners" do let(:runner) { FactoryGirl.create :ci_runner } before do - @project1 = FactoryGirl.create(:ci_project) - @project2 = FactoryGirl.create(:ci_project) - visit ci_admin_runner_path(runner) + @project1 = FactoryGirl.create(:empty_project) + @project2 = FactoryGirl.create(:empty_project) + visit admin_runner_path(runner) end describe 'runner info' do @@ -53,7 +53,7 @@ describe "Admin Runners" do describe 'search' do before do search_form = find('#runner-projects-search') - search_form.fill_in 'search', with: @project1.gl_project.name + search_form.fill_in 'search', with: @project1.name search_form.click_button 'Search' end diff --git a/spec/features/builds_spec.rb b/spec/features/builds_spec.rb index 1f99a808f87..61d81cb0c8e 100644 --- a/spec/features/builds_spec.rb +++ b/spec/features/builds_spec.rb @@ -7,15 +7,15 @@ describe "Builds" do login_as(:user) @commit = FactoryGirl.create :ci_commit @build = FactoryGirl.create :ci_build, commit: @commit - @gl_project = @commit.project.gl_project - @gl_project.team << [@user, :master] + @project = @commit.project + @project.team << [@user, :master] end describe "GET /:project/builds" do context "Running scope" do before do @build.run! - visit namespace_project_builds_path(@gl_project.namespace, @gl_project) + visit namespace_project_builds_path(@project.namespace, @project) end it { expect(page).to have_content 'Running' } @@ -28,7 +28,7 @@ describe "Builds" do context "Finished scope" do before do @build.run! - visit namespace_project_builds_path(@gl_project.namespace, @gl_project, scope: :finished) + visit namespace_project_builds_path(@project.namespace, @project, scope: :finished) end it { expect(page).to have_content 'No builds to show' } @@ -37,8 +37,8 @@ describe "Builds" do context "All builds" do before do - @gl_project.ci_builds.running_or_pending.each(&:success) - visit namespace_project_builds_path(@gl_project.namespace, @gl_project, scope: :all) + @project.ci_builds.running_or_pending.each(&:success) + visit namespace_project_builds_path(@project.namespace, @project, scope: :all) end it { expect(page).to have_content 'All' } @@ -52,7 +52,7 @@ describe "Builds" do describe "POST /:project/builds/:id/cancel_all" do before do @build.run! - visit namespace_project_builds_path(@gl_project.namespace, @gl_project) + visit namespace_project_builds_path(@project.namespace, @project) click_link "Cancel running" end @@ -62,7 +62,7 @@ describe "Builds" do describe "GET /:project/builds/:id" do before do - visit namespace_project_build_path(@gl_project.namespace, @gl_project, @build) + visit namespace_project_build_path(@project.namespace, @project, @build) end it { expect(page).to have_content @commit.sha[0..7] } @@ -72,7 +72,7 @@ describe "Builds" do context "Download artifacts" do before do @build.update_attributes(artifacts_file: artifacts_file) - visit namespace_project_build_path(@gl_project.namespace, @gl_project, @build) + visit namespace_project_build_path(@project.namespace, @project, @build) end it { expect(page).to have_content 'Download artifacts' } @@ -82,7 +82,7 @@ describe "Builds" do describe "POST /:project/builds/:id/cancel" do before do @build.run! - visit namespace_project_build_path(@gl_project.namespace, @gl_project, @build) + visit namespace_project_build_path(@project.namespace, @project, @build) click_link "Cancel" end @@ -93,7 +93,7 @@ describe "Builds" do describe "POST /:project/builds/:id/retry" do before do @build.run! - visit namespace_project_build_path(@gl_project.namespace, @gl_project, @build) + visit namespace_project_build_path(@project.namespace, @project, @build) click_link "Cancel" click_link 'Retry' end @@ -105,7 +105,7 @@ describe "Builds" do describe "GET /:project/builds/:id/download" do before do @build.update_attributes(artifacts_file: artifacts_file) - visit namespace_project_build_path(@gl_project.namespace, @gl_project, @build) + visit namespace_project_build_path(@project.namespace, @project, @build) click_link 'Download artifacts' end diff --git a/spec/features/ci/admin/events_spec.rb b/spec/features/ci/admin/events_spec.rb deleted file mode 100644 index a7e75cc4f6b..00000000000 --- a/spec/features/ci/admin/events_spec.rb +++ /dev/null @@ -1,20 +0,0 @@ -require 'spec_helper' - -describe "Admin Events" do - let(:event) { FactoryGirl.create :ci_admin_event } - - before do - skip_ci_admin_auth - login_as :user - end - - describe "GET /admin/events" do - before do - event - visit ci_admin_events_path - end - - it { expect(page).to have_content "Events" } - it { expect(page).to have_content event.description } - end -end diff --git a/spec/features/ci/admin/projects_spec.rb b/spec/features/ci/admin/projects_spec.rb deleted file mode 100644 index b88f55a6807..00000000000 --- a/spec/features/ci/admin/projects_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -require 'spec_helper' - -describe "Admin Projects" do - let(:project) { FactoryGirl.create :ci_project } - - before do - skip_ci_admin_auth - login_as :user - end - - describe "GET /admin/projects" do - before do - project - visit ci_admin_projects_path - end - - it { expect(page).to have_content "Projects" } - end -end diff --git a/spec/features/ci_settings_spec.rb b/spec/features/ci_settings_spec.rb deleted file mode 100644 index 7e25e883018..00000000000 --- a/spec/features/ci_settings_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -require 'spec_helper' - -describe "CI settings" do - let(:user) { create(:user) } - before { login_as(user) } - - before do - @project = FactoryGirl.create :ci_project - @gl_project = @project.gl_project - @gl_project.team << [user, :master] - visit edit_namespace_project_ci_settings_path(@gl_project.namespace, @gl_project) - end - - it { expect(page).to have_content 'Build Schedule' } - - it "updates configuration" do - fill_in 'Timeout', with: '70' - click_button 'Save changes' - expect(page).to have_content 'was successfully updated' - expect(find_field('Timeout').value).to eq '70' - end -end diff --git a/spec/features/commits_spec.rb b/spec/features/commits_spec.rb index 90739cd6a28..cc0d4c150fe 100644 --- a/spec/features/commits_spec.rb +++ b/spec/features/commits_spec.rb @@ -9,8 +9,7 @@ describe "Commits" do before do login_as :user project.team << [@user, :master] - @ci_project = project.ensure_gitlab_ci_project - @commit = FactoryGirl.create :ci_commit, gl_project: project, sha: project.commit.sha + @commit = FactoryGirl.create :ci_commit, project: project, sha: project.commit.sha @build = FactoryGirl.create :ci_build, commit: @commit @generic_status = FactoryGirl.create :generic_commit_status, commit: @commit end diff --git a/spec/features/ci/lint_spec.rb b/spec/features/lint_spec.rb index 5d8f56e2cfb..5d8f56e2cfb 100644 --- a/spec/features/ci/lint_spec.rb +++ b/spec/features/lint_spec.rb diff --git a/spec/features/runners_spec.rb b/spec/features/runners_spec.rb index b0259026630..a4562f2fae8 100644 --- a/spec/features/runners_spec.rb +++ b/spec/features/runners_spec.rb @@ -8,24 +8,24 @@ describe "Runners" do describe "specific runners" do before do - @project = FactoryGirl.create :ci_project - @project.gl_project.team << [user, :master] + @project = FactoryGirl.create :empty_project, shared_runners_enabled: false + @project.team << [user, :master] - @project2 = FactoryGirl.create :ci_project - @project2.gl_project.team << [user, :master] + @project2 = FactoryGirl.create :empty_project + @project2.team << [user, :master] - @project3 = FactoryGirl.create :ci_project - @project3.gl_project.team << [user, :developer] + @project3 = FactoryGirl.create :empty_project + @project3.team << [user, :developer] @shared_runner = FactoryGirl.create :ci_shared_runner @specific_runner = FactoryGirl.create :ci_specific_runner @specific_runner2 = FactoryGirl.create :ci_specific_runner @specific_runner3 = FactoryGirl.create :ci_specific_runner - @project.runners << @specific_runner - @project2.runners << @specific_runner2 - @project3.runners << @specific_runner3 + @project.ci_runners << @specific_runner + @project2.ci_runners << @specific_runner2 + @project3.ci_runners << @specific_runner3 - visit runners_path(@project.gl_project) + visit runners_path(@project) end before do @@ -48,8 +48,8 @@ describe "Runners" do end it "disables specific runner for project" do - @project2.runners << @specific_runner - visit runners_path(@project.gl_project) + @project2.ci_runners << @specific_runner + visit runners_path(@project) within ".activated-specific-runners" do click_on "Disable for this project" @@ -69,9 +69,9 @@ describe "Runners" do describe "shared runners" do before do - @project = FactoryGirl.create :ci_project - @project.gl_project.team << [user, :master] - visit runners_path(@project.gl_project) + @project = FactoryGirl.create :empty_project, shared_runners_enabled: false + @project.team << [user, :master] + visit runners_path(@project) end it "enables shared runners" do @@ -82,14 +82,14 @@ describe "Runners" do describe "show page" do before do - @project = FactoryGirl.create :ci_project - @project.gl_project.team << [user, :master] + @project = FactoryGirl.create :empty_project + @project.team << [user, :master] @specific_runner = FactoryGirl.create :ci_specific_runner - @project.runners << @specific_runner + @project.ci_runners << @specific_runner end it "shows runner information" do - visit runners_path(@project.gl_project) + visit runners_path(@project) click_on @specific_runner.short_sha expect(page).to have_content(@specific_runner.platform) end diff --git a/spec/features/triggers_spec.rb b/spec/features/triggers_spec.rb index 69492d58878..b0705a45aee 100644 --- a/spec/features/triggers_spec.rb +++ b/spec/features/triggers_spec.rb @@ -5,25 +5,24 @@ describe 'Triggers' do before { login_as(user) } before do - @project = FactoryGirl.create :ci_project - @gl_project = @project.gl_project - @gl_project.team << [user, :master] - visit namespace_project_triggers_path(@gl_project.namespace, @gl_project) + @project = FactoryGirl.create :empty_project + @project.team << [user, :master] + visit namespace_project_triggers_path(@project.namespace, @project) end context 'create a trigger' do before do click_on 'Add Trigger' - expect(@project.triggers.count).to eq(1) + expect(@project.ci_triggers.count).to eq(1) end it 'contains trigger token' do - expect(page).to have_content(@project.triggers.first.token) + expect(page).to have_content(@project.ci_triggers.first.token) end it 'revokes the trigger' do click_on 'Revoke' - expect(@project.triggers.count).to eq(0) + expect(@project.ci_triggers.count).to eq(0) end end end diff --git a/spec/features/variables_spec.rb b/spec/features/variables_spec.rb index adb602f3edd..a6e68eeefbc 100644 --- a/spec/features/variables_spec.rb +++ b/spec/features/variables_spec.rb @@ -6,20 +6,19 @@ describe "Variables" do describe "specific runners" do before do - @project = FactoryGirl.create :ci_project - @gl_project = @project.gl_project - @gl_project.team << [user, :master] + @project = FactoryGirl.create :empty_project + @project.team << [user, :master] end it "creates variable", js: true do - visit namespace_project_variables_path(@gl_project.namespace, @gl_project) + visit namespace_project_variables_path(@project.namespace, @project) click_on "Add a variable" fill_in "Key", with: "SECRET_KEY" fill_in "Value", with: "SECRET_VALUE" click_on "Save changes" expect(page).to have_content("Variables were successfully updated.") - expect(@project.variables.count).to eq(1) + expect(@project.ci_variables.count).to eq(1) end end end diff --git a/spec/lib/gitlab/backend/grack_auth_spec.rb b/spec/lib/gitlab/backend/grack_auth_spec.rb index 73458735ad9..2dd27464de7 100644 --- a/spec/lib/gitlab/backend/grack_auth_spec.rb +++ b/spec/lib/gitlab/backend/grack_auth_spec.rb @@ -191,15 +191,10 @@ describe Grack::Auth, lib: true do context "when a gitlab ci token is provided" do let(:token) { "123" } - let(:gitlab_ci_project) { FactoryGirl.create :ci_project, token: token } + let(:project) { FactoryGirl.create :empty_project, token: token } before do - project.gitlab_ci_project = gitlab_ci_project - project.save - - gitlab_ci_service = project.build_gitlab_ci_service - gitlab_ci_service.active = true - gitlab_ci_service.save + project.update_attributes(token: token, builds_enabled: true) env["HTTP_AUTHORIZATION"] = ActionController::HttpAuthentication::Basic.encode_credentials("gitlab-ci-token", token) end diff --git a/spec/lib/gitlab/build_data_builder_spec.rb b/spec/lib/gitlab/build_data_builder_spec.rb index af2de207eba..839b30f1ff4 100644 --- a/spec/lib/gitlab/build_data_builder_spec.rb +++ b/spec/lib/gitlab/build_data_builder_spec.rb @@ -14,7 +14,7 @@ describe 'Gitlab::BuildDataBuilder' do it { expect(data[:tag]).to eq(build.tag) } it { expect(data[:build_id]).to eq(build.id) } it { expect(data[:build_status]).to eq(build.status) } - it { expect(data[:project_id]).to eq(build.gl_project.id) } - it { expect(data[:project_name]).to eq(build.gl_project.name_with_namespace) } + it { expect(data[:project_id]).to eq(build.project.id) } + it { expect(data[:project_name]).to eq(build.project.name_with_namespace) } end end diff --git a/spec/models/application_setting_spec.rb b/spec/models/application_setting_spec.rb index b67b84959d9..5f64453a35f 100644 --- a/spec/models/application_setting_spec.rb +++ b/spec/models/application_setting_spec.rb @@ -73,26 +73,4 @@ describe ApplicationSetting, models: true do expect(setting.restricted_signup_domains).to eq(['example.com', '*.example.com']) end end - - context 'shared runners' do - let(:gl_project) { create(:empty_project) } - - before do - allow_any_instance_of(Project).to receive(:current_application_settings).and_return(setting) - end - - subject { gl_project.ensure_gitlab_ci_project.shared_runners_enabled } - - context 'enabled' do - before { setting.update_attributes(shared_runners_enabled: true) } - - it { is_expected.to be_truthy } - end - - context 'disabled' do - before { setting.update_attributes(shared_runners_enabled: false) } - - it { is_expected.to be_falsey } - end - end end diff --git a/spec/models/build_spec.rb b/spec/models/build_spec.rb index 70c831b7cbe..70a63c05b22 100644 --- a/spec/models/build_spec.rb +++ b/spec/models/build_spec.rb @@ -26,9 +26,8 @@ require 'spec_helper' describe Ci::Build, models: true do - let(:project) { FactoryGirl.create :ci_project } - let(:gl_project) { FactoryGirl.create :empty_project, gitlab_ci_project: project } - let(:commit) { FactoryGirl.create :ci_commit, gl_project: gl_project } + let(:project) { FactoryGirl.create :empty_project } + let(:commit) { FactoryGirl.create :ci_commit, project: project } let(:build) { FactoryGirl.create :ci_build, commit: commit } it { is_expected.to validate_presence_of :ref } @@ -120,11 +119,12 @@ describe Ci::Build, models: true do end end - describe :timeout do - subject { build.timeout } - - it { is_expected.to eq(commit.project.timeout) } - end + # TODO: build timeout + # describe :timeout do + # subject { build.timeout } + # + # it { is_expected.to eq(commit.project.timeout) } + # end describe :options do let(:options) do @@ -140,11 +140,12 @@ describe Ci::Build, models: true do it { is_expected.to eq(options) } end - describe :allow_git_fetch do - subject { build.allow_git_fetch } - - it { is_expected.to eq(project.allow_git_fetch) } - end + # TODO: allow_git_fetch + # describe :allow_git_fetch do + # subject { build.allow_git_fetch } + # + # it { is_expected.to eq(project.allow_git_fetch) } + # end describe :project do subject { build.project } @@ -164,12 +165,6 @@ describe Ci::Build, models: true do it { is_expected.to eq(project.name) } end - describe :repo_url do - subject { build.repo_url } - - it { is_expected.to eq(project.repo_url_with_auth) } - end - describe :extract_coverage do context 'valid content & regex' do subject { build.extract_coverage('Coverage 1033 / 1051 LOC (98.29%) covered', '\(\d+.\d+\%\) covered') } @@ -237,7 +232,7 @@ describe Ci::Build, models: true do end before do - build.project.variables << Ci::Variable.new(key: 'SECRET_KEY', value: 'secret_value') + build.project.ci_variables << Ci::Variable.new(key: 'SECRET_KEY', value: 'secret_value') end it { is_expected.to eq(predefined_variables + yaml_variables + secure_variables) } @@ -266,44 +261,10 @@ describe Ci::Build, models: true do end end - describe :project_recipients do - let(:pusher_email) { 'pusher@gitlab.test' } - let(:user) { User.new(notification_email: pusher_email) } - subject { build.project_recipients } - - before do - build.update_attributes(user: user) - end - - it 'should return pusher_email as only recipient when no additional recipients are given' do - project.update_attributes(email_add_pusher: true, - email_recipients: '') - is_expected.to eq([pusher_email]) - end - - it 'should return pusher_email and additional recipients' do - project.update_attributes(email_add_pusher: true, - email_recipients: 'rec1 rec2') - is_expected.to eq(['rec1', 'rec2', pusher_email]) - end - - it 'should return recipients' do - project.update_attributes(email_add_pusher: false, - email_recipients: 'rec1 rec2') - is_expected.to eq(['rec1', 'rec2']) - end - - it 'should return unique recipients only' do - project.update_attributes(email_add_pusher: true, - email_recipients: "rec1 rec1 #{pusher_email}") - is_expected.to eq(['rec1', pusher_email]) - end - end - describe :can_be_served? do let(:runner) { FactoryGirl.create :ci_specific_runner } - before { build.project.runners << runner } + before { build.project.ci_runners << runner } context 'runner without tags' do it 'can handle builds without tags' do @@ -346,7 +307,7 @@ describe Ci::Build, models: true do let(:runner) { FactoryGirl.create :ci_specific_runner } before do - build.project.runners << runner + build.project.ci_runners << runner runner.update_attributes(contacted_at: 1.second.ago) end @@ -383,7 +344,7 @@ describe Ci::Build, models: true do let(:runner) { FactoryGirl.create :ci_specific_runner, contacted_at: 1.second.ago } before do - build.project.runners << runner + build.project.ci_runners << runner runner.save end @@ -415,4 +376,18 @@ describe Ci::Build, models: true do is_expected.to_not be_nil end end + + describe :repo_url do + let(:build) { FactoryGirl.create :ci_build } + let(:project) { build.project } + + subject { build.repo_url } + + it { is_expected.to be_a(String) } + it { is_expected.to end_with(".git") } + it { is_expected.to start_with(project.web_url[0..6]) } + it { is_expected.to include(project.token) } + it { is_expected.to include('gitlab-ci-token') } + it { is_expected.to include(project.web_url[7..-1]) } + end end diff --git a/spec/models/ci/commit_spec.rb b/spec/models/ci/commit_spec.rb index 89813cdf7fc..ac61c8fb525 100644 --- a/spec/models/ci/commit_spec.rb +++ b/spec/models/ci/commit_spec.rb @@ -13,17 +13,16 @@ # tag :boolean default(FALSE) # yaml_errors :text # committed_at :datetime -# gl_project_id :integer +# project_id :integer # require 'spec_helper' describe Ci::Commit, models: true do - let(:project) { FactoryGirl.create :ci_project } - let(:gl_project) { FactoryGirl.create :empty_project, gitlab_ci_project: project } - let(:commit) { FactoryGirl.create :ci_commit, gl_project: gl_project } + let(:project) { FactoryGirl.create :empty_project } + let(:commit) { FactoryGirl.create :ci_commit, project: project } - it { is_expected.to belong_to(:gl_project) } + it { is_expected.to belong_to(:project) } it { is_expected.to have_many(:statuses) } it { is_expected.to have_many(:trigger_requests) } it { is_expected.to have_many(:builds) } @@ -37,16 +36,16 @@ describe Ci::Commit, models: true do let(:project) { FactoryGirl.create :empty_project } 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 + commit1 = FactoryGirl.create :ci_commit, committed_at: 1.hour.ago, project: project + commit2 = FactoryGirl.create :ci_commit, committed_at: 2.hour.ago, project: project expect(project.ci_commits.ordered).to eq([commit2, commit1]) end it 'returns commits ordered by committed_at and id, with nulls last' do - commit1 = FactoryGirl.create :ci_commit, committed_at: 1.hour.ago, gl_project: project - 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 + commit1 = FactoryGirl.create :ci_commit, committed_at: 1.hour.ago, project: project + commit2 = FactoryGirl.create :ci_commit, committed_at: nil, project: project + commit3 = FactoryGirl.create :ci_commit, committed_at: 2.hour.ago, project: project + commit4 = FactoryGirl.create :ci_commit, committed_at: nil, project: project expect(project.ci_commits.ordered).to eq([commit2, commit4, commit3, commit1]) end end @@ -162,7 +161,7 @@ describe Ci::Commit, models: true do end describe :create_builds do - let!(:commit) { FactoryGirl.create :ci_commit, gl_project: gl_project } + let!(:commit) { FactoryGirl.create :ci_commit, project: project } def create_builds(trigger_request = nil) commit.create_builds('master', false, nil, trigger_request) @@ -390,9 +389,8 @@ describe Ci::Commit, models: true do end describe "coverage" do - let(:project) { FactoryGirl.create :ci_project, coverage_regex: "/.*/" } - let(:gl_project) { FactoryGirl.create :empty_project, gitlab_ci_project: project } - let(:commit) { FactoryGirl.create :ci_commit, gl_project: gl_project } + let(:project) { FactoryGirl.create :empty_project, build_coverage_regex: "/.*/" } + let(:commit) { FactoryGirl.create :ci_commit, project: project } it "calculates average when there are two builds with coverage" do FactoryGirl.create :ci_build, name: "rspec", coverage: 30, commit: commit diff --git a/spec/models/ci/project_spec.rb b/spec/models/ci/project_spec.rb deleted file mode 100644 index e358aa02741..00000000000 --- a/spec/models/ci/project_spec.rb +++ /dev/null @@ -1,244 +0,0 @@ -# == Schema Information -# -# Table name: ci_projects -# -# id :integer not null, primary key -# name :string(255) -# timeout :integer default(3600), not null -# created_at :datetime -# updated_at :datetime -# token :string(255) -# default_ref :string(255) -# path :string(255) -# always_build :boolean default(FALSE), not null -# polling_interval :integer -# public :boolean default(FALSE), not null -# ssh_url_to_repo :string(255) -# gitlab_id :integer -# allow_git_fetch :boolean default(TRUE), not null -# email_recipients :string(255) default(""), not null -# email_add_pusher :boolean default(TRUE), not null -# email_only_broken_builds :boolean default(TRUE), not null -# skip_refs :string(255) -# coverage_regex :string(255) -# shared_runners_enabled :boolean default(FALSE) -# generated_yaml_config :text -# - -require 'spec_helper' - -describe Ci::Project, models: true do - let(:project) { FactoryGirl.create :ci_project } - let(:gl_project) { project.gl_project } - subject { project } - - it { is_expected.to have_many(:runner_projects) } - it { is_expected.to have_many(:runners) } - 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 validate_presence_of :timeout } - it { is_expected.to validate_presence_of :gitlab_id } - - describe 'before_validation' do - it 'should set an random token if none provided' do - project = FactoryGirl.create :ci_project_without_token - expect(project.token).not_to eq("") - end - - it 'should not set an random toke if one provided' do - project = FactoryGirl.create :ci_project - expect(project.token).to eq("iPWx6WM4lhHNedGfBpPJNP") - end - end - - describe :name_with_namespace do - subject { project.name_with_namespace } - - it { is_expected.to eq(project.name) } - it { is_expected.to eq(gl_project.name_with_namespace) } - end - - describe :path_with_namespace do - subject { project.path_with_namespace } - - it { is_expected.to eq(project.path) } - it { is_expected.to eq(gl_project.path_with_namespace) } - end - - describe :path_with_namespace do - subject { project.web_url } - - it { is_expected.to eq(gl_project.web_url) } - end - - describe :web_url do - subject { project.web_url } - - it { is_expected.to eq(project.gitlab_url) } - it { is_expected.to eq(gl_project.web_url) } - end - - describe :http_url_to_repo do - subject { project.http_url_to_repo } - - it { is_expected.to eq(gl_project.http_url_to_repo) } - end - - describe :ssh_url_to_repo do - subject { project.ssh_url_to_repo } - - it { is_expected.to eq(gl_project.ssh_url_to_repo) } - end - - describe :commits do - subject { project.commits } - - before do - FactoryGirl.create :ci_commit, committed_at: 1.hour.ago, gl_project: gl_project - end - - it { is_expected.to eq(gl_project.ci_commits) } - end - - describe :builds do - subject { project.builds } - - before do - commit = FactoryGirl.create :ci_commit, committed_at: 1.hour.ago, gl_project: gl_project - FactoryGirl.create :ci_build, commit: commit - end - - it { is_expected.to eq(gl_project.ci_builds) } - end - - describe "ordered_by_last_commit_date" do - it "returns ordered projects" do - newest_project = FactoryGirl.create :empty_project - newest_ci_project = newest_project.ensure_gitlab_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, 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_ci_project, oldest_ci_project, ci_project_without_commits]) - end - end - - context :valid_project do - let(:commit) { FactoryGirl.create(:ci_commit) } - - context :project_with_commit_and_builds do - let(:project) { commit.project } - - before do - FactoryGirl.create(:ci_build, commit: commit) - end - - it { expect(project.status).to eq('pending') } - it { expect(project.last_commit).to be_kind_of(Ci::Commit) } - it { expect(project.human_status).to eq('pending') } - end - end - - describe '#email_notification?' do - it do - project = FactoryGirl.create :ci_project, email_add_pusher: true - expect(project.email_notification?).to eq(true) - end - - it do - project = FactoryGirl.create :ci_project, email_add_pusher: false, email_recipients: 'test tesft' - expect(project.email_notification?).to eq(true) - end - - it do - project = FactoryGirl.create :ci_project, email_add_pusher: false, email_recipients: '' - expect(project.email_notification?).to eq(false) - end - end - - describe '#broken_or_success?' do - it do - project = FactoryGirl.create :ci_project, email_add_pusher: true - allow(project).to receive(:broken?).and_return(true) - allow(project).to receive(:success?).and_return(true) - expect(project.broken_or_success?).to eq(true) - end - - it do - project = FactoryGirl.create :ci_project, email_add_pusher: true - allow(project).to receive(:broken?).and_return(true) - allow(project).to receive(:success?).and_return(false) - expect(project.broken_or_success?).to eq(true) - end - - it do - project = FactoryGirl.create :ci_project, email_add_pusher: true - allow(project).to receive(:broken?).and_return(false) - allow(project).to receive(:success?).and_return(true) - expect(project.broken_or_success?).to eq(true) - end - - it do - project = FactoryGirl.create :ci_project, email_add_pusher: true - allow(project).to receive(:broken?).and_return(false) - allow(project).to receive(:success?).and_return(false) - expect(project.broken_or_success?).to eq(false) - end - end - - describe :repo_url_with_auth do - let(:project) { FactoryGirl.create :ci_project } - subject { project.repo_url_with_auth } - - it { is_expected.to be_a(String) } - it { is_expected.to end_with(".git") } - it { is_expected.to start_with(project.gitlab_url[0..6]) } - it { is_expected.to include(project.token) } - it { is_expected.to include('gitlab-ci-token') } - it { is_expected.to include(project.gitlab_url[7..-1]) } - end - - describe :any_runners do - it "there are no runners available" do - project = FactoryGirl.create(:ci_project) - expect(project.any_runners?).to be_falsey - end - - it "there is a specific runner" do - project = FactoryGirl.create(:ci_project) - project.runners << FactoryGirl.create(:ci_specific_runner) - expect(project.any_runners?).to be_truthy - end - - it "there is a shared runner" do - project = FactoryGirl.create(:ci_project, shared_runners_enabled: true) - FactoryGirl.create(:ci_shared_runner) - expect(project.any_runners?).to be_truthy - end - - it "there is a shared runner, but they are prohibited to use" do - project = FactoryGirl.create(:ci_project) - FactoryGirl.create(:ci_shared_runner) - expect(project.any_runners?).to be_falsey - end - - it "checks the presence of specific runner" do - project = FactoryGirl.create(:ci_project) - specific_runner = FactoryGirl.create(:ci_specific_runner) - project.runners << specific_runner - expect(project.any_runners? { |runner| runner == specific_runner }).to be_truthy - end - - it "checks the presence of shared runner" do - project = FactoryGirl.create(:ci_project, shared_runners_enabled: true) - shared_runner = FactoryGirl.create(:ci_shared_runner) - expect(project.any_runners? { |runner| runner == shared_runner }).to be_truthy - end - end -end diff --git a/spec/models/ci/runner_spec.rb b/spec/models/ci/runner_spec.rb index 6ebb5e86863..33388f97826 100644 --- a/spec/models/ci/runner_spec.rb +++ b/spec/models/ci/runner_spec.rb @@ -38,7 +38,7 @@ describe Ci::Runner, models: true do end describe :assign_to do - let!(:project) { FactoryGirl.create :ci_project } + let!(:project) { FactoryGirl.create :empty_project } let!(:shared_runner) { FactoryGirl.create(:ci_shared_runner) } before { shared_runner.assign_to(project) } @@ -116,18 +116,18 @@ describe Ci::Runner, models: true do describe "belongs_to_one_project?" do it "returns false if there are two projects runner assigned to" do runner = FactoryGirl.create(:ci_specific_runner) - project = FactoryGirl.create(:ci_project) - project1 = FactoryGirl.create(:ci_project) - project.runners << runner - project1.runners << runner + project = FactoryGirl.create(:empty_project) + project1 = FactoryGirl.create(:empty_project) + project.ci_runners << runner + project1.ci_runners << runner expect(runner.belongs_to_one_project?).to be_falsey end it "returns true" do runner = FactoryGirl.create(:ci_specific_runner) - project = FactoryGirl.create(:ci_project) - project.runners << runner + project = FactoryGirl.create(:empty_project) + project.ci_runners << runner expect(runner.belongs_to_one_project?).to be_truthy end diff --git a/spec/models/ci/trigger_spec.rb b/spec/models/ci/trigger_spec.rb index 61eb3c08296..cb2f51e2011 100644 --- a/spec/models/ci/trigger_spec.rb +++ b/spec/models/ci/trigger_spec.rb @@ -13,7 +13,7 @@ require 'spec_helper' describe Ci::Trigger, models: true do - let(:project) { FactoryGirl.create :ci_project } + let(:project) { FactoryGirl.create :empty_project } describe 'before_validation' do it 'should set an random token if none provided' do diff --git a/spec/models/commit_status_spec.rb b/spec/models/commit_status_spec.rb index 5e311ead28b..6131191f0fa 100644 --- a/spec/models/commit_status_spec.rb +++ b/spec/models/commit_status_spec.rb @@ -44,7 +44,7 @@ describe CommitStatus, models: true do it { is_expected.to delegate_method(:sha).to(:commit) } it { is_expected.to delegate_method(:short_sha).to(:commit) } - it { is_expected.to delegate_method(:gl_project).to(:commit) } + it { is_expected.to delegate_method(:project).to(:commit) } it { is_expected.to respond_to :success? } it { is_expected.to respond_to :failed? } diff --git a/spec/models/project_services/gitlab_ci_service_spec.rb b/spec/models/project_services/gitlab_ci_service_spec.rb deleted file mode 100644 index 835bf364050..00000000000 --- a/spec/models/project_services/gitlab_ci_service_spec.rb +++ /dev/null @@ -1,57 +0,0 @@ -# == Schema Information -# -# Table name: services -# -# id :integer not null, primary key -# type :string(255) -# title :string(255) -# project_id :integer -# created_at :datetime -# updated_at :datetime -# active :boolean default(FALSE), not null -# properties :text -# template :boolean default(FALSE) -# push_events :boolean default(TRUE) -# issues_events :boolean default(TRUE) -# merge_requests_events :boolean default(TRUE) -# tag_push_events :boolean default(TRUE) -# note_events :boolean default(TRUE), not null -# - -require 'spec_helper' - -describe GitlabCiService, models: true do - describe 'associations' do - it { is_expected.to belong_to(:project) } - it { is_expected.to have_one(:service_hook) } - end - - describe 'commits methods' do - before do - @ci_project = create(:ci_project) - @service = GitlabCiService.new - allow(@service).to receive_messages( - service_hook: true, - project_url: 'http://ci.gitlab.org/projects/2', - token: 'verySecret', - project: @ci_project.gl_project - ) - end - - describe :build_page do - it { expect(@service.build_page("2ab7834c", 'master')).to eq("http://localhost/#{@ci_project.gl_project.path_with_namespace}/commit/2ab7834c/builds")} - end - - describe "execute" do - let(:user) { create(:user, username: 'username') } - let(:project) { create(:project, name: 'project') } - let(:push_sample_data) { Gitlab::PushDataBuilder.build_sample(project, user) } - - it "calls CreateCommitService" do - expect_any_instance_of(Ci::CreateCommitService).to receive(:execute).with(@ci_project, user, push_sample_data) - - @service.execute(push_sample_data) - end - end - end -end diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 6ddb0e2b8f7..ee106b11fbb 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -54,6 +54,13 @@ describe Project, models: true do it { is_expected.to have_one(:slack_service).dependent(:destroy) } it { is_expected.to have_one(:pushover_service).dependent(:destroy) } it { is_expected.to have_one(:asana_service).dependent(:destroy) } + it { is_expected.to have_many(:ci_commits) } + it { is_expected.to have_many(:ci_statuses) } + it { is_expected.to have_many(:ci_builds) } + it { is_expected.to have_many(:ci_runner_projects) } + it { is_expected.to have_many(:ci_runners) } + it { is_expected.to have_many(:ci_variables) } + it { is_expected.to have_many(:ci_triggers) } end describe 'modules' do @@ -88,6 +95,18 @@ describe Project, models: true do expect(project2.errors[:limit_reached].first).to match(/Your project limit is 0/) end end + + describe 'project token' do + it 'should set an random token if none provided' do + project = FactoryGirl.create :empty_project, token: '' + expect(project.token).not_to eq('') + end + + it 'should not set an random toke if one provided' do + project = FactoryGirl.create :empty_project, token: 'my-token' + expect(project.token).to eq('my-token') + end + end describe 'Respond to' do it { is_expected.to respond_to(:url_to_repo) } @@ -395,12 +414,7 @@ describe Project, models: true do describe :ci_commit do let(:project) { create :project } - let(:commit) { create :ci_commit, gl_project: project } - - before do - project.ensure_gitlab_ci_project - project.create_gitlab_ci_service(active: true) - end + let(:commit) { create :ci_commit, project: project } it { expect(project.ci_commit(commit.sha)).to eq(commit) } end @@ -412,9 +426,7 @@ describe Project, models: true do subject { project.builds_enabled } - it { is_expected.to eq(project.gitlab_ci_service.active) } it { expect(project.builds_enabled?).to be_truthy } - it { expect(project.gitlab_ci_project).to be_a(Ci::Project) } end describe '.trending' do @@ -475,4 +487,65 @@ describe Project, models: true do it { is_expected.to eq([]) } end end + + context 'shared runners by default' do + let(:project) { create(:empty_project) } + + subject { project.shared_runners_enabled } + + context 'are enabled' do + before { stub_application_setting(shared_runners_enabled: true) } + + it { is_expected.to be_truthy } + end + + context 'are disabled' do + before { stub_application_setting(shared_runners_enabled: false) } + + it { is_expected.to be_falsey } + end + end + + describe :any_runners do + let(:project) { create(:empty_project, shared_runners_enabled: shared_runners_enabled) } + let(:specific_runner) { create(:ci_specific_runner) } + let(:shared_runner) { create(:ci_shared_runner) } + + context 'for shared runners disabled' do + let(:shared_runners_enabled) { false } + + it 'there are no runners available' do + expect(project.any_runners?).to be_falsey + end + + it 'there is a specific runner' do + project.ci_runners << specific_runner + expect(project.any_runners?).to be_truthy + end + + it 'there is a shared runner, but they are prohibited to use' do + shared_runner + expect(project.any_runners?).to be_falsey + end + + it 'checks the presence of specific runner' do + project.ci_runners << specific_runner + expect(project.any_runners? { |runner| runner == specific_runner }).to be_truthy + end + end + + context 'for shared runners enabled' do + let(:shared_runners_enabled) { true } + + it 'there is a shared runner' do + shared_runner + expect(project.any_runners?).to be_truthy + end + + it 'checks the presence of shared runner' do + shared_runner + expect(project.any_runners? { |runner| runner == shared_runner }).to be_truthy + end + end + end end diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb index 24b765f4979..e784b7d1f2d 100644 --- a/spec/requests/api/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb @@ -86,18 +86,6 @@ describe API::API, api: true do expect(json_response).to be_an Array expect(json_response.first['id']).to eq(project3.id) end - - it 'returns projects in the correct order when ci_enabled_first parameter is passed' do - [project, project2, project3].each do |project| - project.builds_enabled = false - project.build_missing_services - end - project2.builds_enabled = true - get api('/projects', user), { ci_enabled_first: 'true' } - expect(response.status).to eq(200) - expect(json_response).to be_an Array - expect(json_response.first['id']).to eq(project2.id) - end end end end diff --git a/spec/requests/ci/api/builds_spec.rb b/spec/requests/ci/api/builds_spec.rb index c2be045099d..0aa9981ea8d 100644 --- a/spec/requests/ci/api/builds_spec.rb +++ b/spec/requests/ci/api/builds_spec.rb @@ -4,8 +4,7 @@ describe Ci::API::API do include ApiHelpers let(:runner) { FactoryGirl.create(:ci_runner, tag_list: ["mysql", "ruby"]) } - let(:project) { FactoryGirl.create(:ci_project) } - let(:gl_project) { project.gl_project } + let(:project) { FactoryGirl.create(:empty_project) } before do stub_ci_commit_to_return_yaml_file @@ -13,16 +12,15 @@ describe Ci::API::API do describe "Builds API for runners" do let(:shared_runner) { FactoryGirl.create(:ci_runner, token: "SharedRunner") } - let(:shared_project) { FactoryGirl.create(:ci_project, name: "SharedProject") } - let(:shared_gl_project) { shared_project.gl_project } + let(:shared_project) { FactoryGirl.create(:empty_project, name: "SharedProject") } before do - FactoryGirl.create :ci_runner_project, project_id: project.id, runner_id: runner.id + FactoryGirl.create :ci_runner_project, project: project, runner: runner end describe "POST /builds/register" do it "should start a build" do - commit = FactoryGirl.create(:ci_commit, gl_project: gl_project) + commit = FactoryGirl.create(:ci_commit, project: project) commit.create_builds('master', false, nil) build = commit.builds.first @@ -40,7 +38,7 @@ describe Ci::API::API do end it "should return 404 error if no builds for specific runner" do - commit = FactoryGirl.create(:ci_commit, gl_project: shared_gl_project) + commit = FactoryGirl.create(:ci_commit, project: shared_project) FactoryGirl.create(:ci_build, commit: commit, status: 'pending') post ci_api("/builds/register"), token: runner.token @@ -49,7 +47,7 @@ describe Ci::API::API do end it "should return 404 error if no builds for shared runner" do - commit = FactoryGirl.create(:ci_commit, gl_project: gl_project) + commit = FactoryGirl.create(:ci_commit, project: project) FactoryGirl.create(:ci_build, commit: commit, status: 'pending') post ci_api("/builds/register"), token: shared_runner.token @@ -58,7 +56,7 @@ describe Ci::API::API do end it "returns options" do - commit = FactoryGirl.create(:ci_commit, gl_project: gl_project) + commit = FactoryGirl.create(:ci_commit, project: project) commit.create_builds('master', false, nil) post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin } @@ -68,9 +66,9 @@ describe Ci::API::API do end it "returns variables" do - commit = FactoryGirl.create(:ci_commit, gl_project: gl_project) + commit = FactoryGirl.create(:ci_commit, project: project) commit.create_builds('master', false, nil) - project.variables << Ci::Variable.new(key: "SECRET_KEY", value: "secret_value") + project.ci_variables << Ci::Variable.new(key: "SECRET_KEY", value: "secret_value") post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin } @@ -85,11 +83,11 @@ describe Ci::API::API do it "returns variables for triggers" do trigger = FactoryGirl.create(:ci_trigger, project: project) - commit = FactoryGirl.create(:ci_commit, gl_project: gl_project) + commit = FactoryGirl.create(:ci_commit, project: project) trigger_request = FactoryGirl.create(:ci_trigger_request_with_variables, commit: commit, trigger: trigger) commit.create_builds('master', false, nil, trigger_request) - project.variables << Ci::Variable.new(key: "SECRET_KEY", value: "secret_value") + project.ci_variables << Ci::Variable.new(key: "SECRET_KEY", value: "secret_value") post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin } @@ -106,7 +104,7 @@ describe Ci::API::API do end describe "PUT /builds/:id" do - let(:commit) { FactoryGirl.create(:ci_commit, gl_project: gl_project)} + let(:commit) { FactoryGirl.create(:ci_commit, project: project)} let(:build) { FactoryGirl.create(:ci_build, commit: commit, runner_id: runner.id) } it "should update a running build" do @@ -126,7 +124,7 @@ describe Ci::API::API do context "Artifacts" do let(:file_upload) { fixture_file_upload(Rails.root + 'spec/fixtures/banana_sample.gif', 'image/gif') } let(:file_upload2) { fixture_file_upload(Rails.root + 'spec/fixtures/dk.png', 'image/gif') } - let(:commit) { FactoryGirl.create(:ci_commit, gl_project: gl_project) } + let(:commit) { FactoryGirl.create(:ci_commit, project: project) } let(:build) { FactoryGirl.create(:ci_build, commit: commit, runner_id: runner.id) } let(:authorize_url) { ci_api("/builds/#{build.id}/artifacts/authorize") } let(:post_url) { ci_api("/builds/#{build.id}/artifacts") } diff --git a/spec/requests/ci/api/commits_spec.rb b/spec/requests/ci/api/commits_spec.rb deleted file mode 100644 index aa51ba95bca..00000000000 --- a/spec/requests/ci/api/commits_spec.rb +++ /dev/null @@ -1,65 +0,0 @@ -require 'spec_helper' - -describe Ci::API::API, 'Commits' do - include ApiHelpers - - let(:project) { FactoryGirl.create(:ci_project) } - let(:gl_project) { project.gl_project } - let(:commit) { FactoryGirl.create(:ci_commit, gl_project: gl_project) } - - let(:options) do - { - project_token: project.token, - project_id: project.id - } - end - - describe "GET /commits" do - before { commit } - - it "should return commits per project" do - get ci_api("/commits"), options - - expect(response.status).to eq(200) - expect(json_response.count).to eq(1) - expect(json_response.first["project_id"]).to eq(project.id) - expect(json_response.first["sha"]).to eq(commit.sha) - end - end - - describe "POST /commits" do - let(:data) do - { - "before" => "95790bf891e76fee5e1747ab589903a6a1f80f22", - "after" => "da1560886d4f094c3e6c9ef40349f7d38b5d27d7", - "ref" => "refs/heads/master", - "commits" => [ - { - "id" => "b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327", - "message" => "Update Catalan translation to e38cb41.", - "timestamp" => "2011-12-12T14:27:31+02:00", - "url" => "http://localhost/diaspora/commits/b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327", - "author" => { - "name" => "Jordi Mallach", - "email" => "jordi@softcatala.org", - } - } - ] - } - end - - it "should create a build" do - post ci_api("/commits"), options.merge(data: data) - - expect(response.status).to eq(201) - expect(json_response['sha']).to eq("da1560886d4f094c3e6c9ef40349f7d38b5d27d7") - end - - it "should return 400 error if no data passed" do - post ci_api("/commits"), options - - expect(response.status).to eq(400) - expect(json_response['message']).to eq("400 (Bad request) \"data\" not given") - end - end -end diff --git a/spec/requests/ci/api/projects_spec.rb b/spec/requests/ci/api/projects_spec.rb deleted file mode 100644 index b1fbdac5970..00000000000 --- a/spec/requests/ci/api/projects_spec.rb +++ /dev/null @@ -1,159 +0,0 @@ -require 'spec_helper' - -describe Ci::API::API do - include ApiHelpers - - let(:gitlab_url) { GitlabCi.config.gitlab_ci.url } - let(:user) { create(:user) } - let(:private_token) { user.private_token } - - let(:options) do - { - private_token: private_token, - url: gitlab_url - } - end - - before do - stub_gitlab_calls - end - - context "requests for scoped projects" do - # NOTE: These ids are tied to the actual projects on demo.gitlab.com - describe "GET /projects" do - let!(:project1) { FactoryGirl.create(:ci_project) } - let!(:project2) { FactoryGirl.create(:ci_project) } - - before do - project1.gl_project.team << [user, :developer] - project2.gl_project.team << [user, :developer] - end - - it "should return all projects on the CI instance" do - get ci_api("/projects"), options - expect(response.status).to eq(200) - expect(json_response.count).to eq(2) - expect(json_response.first["id"]).to eq(project1.id) - expect(json_response.last["id"]).to eq(project2.id) - end - end - - describe "GET /projects/owned" do - let!(:gl_project1) {FactoryGirl.create(:empty_project, namespace: user.namespace)} - let!(:gl_project2) {FactoryGirl.create(:empty_project, namespace: user.namespace)} - let!(:project1) { gl_project1.ensure_gitlab_ci_project } - let!(:project2) { gl_project2.ensure_gitlab_ci_project } - - before do - project1.gl_project.team << [user, :developer] - project2.gl_project.team << [user, :developer] - end - - it "should return all projects on the CI instance" do - get ci_api("/projects/owned"), options - - expect(response.status).to eq(200) - expect(json_response.count).to eq(2) - end - end - end - - describe "GET /projects/:id" do - let!(:project) { FactoryGirl.create(:ci_project) } - - before do - project.gl_project.team << [user, :developer] - end - - context "with an existing project" do - it "should retrieve the project info" do - get ci_api("/projects/#{project.id}"), options - expect(response.status).to eq(200) - expect(json_response['id']).to eq(project.id) - end - end - - context "with a non-existing project" do - it "should return 404 error if project not found" do - get ci_api("/projects/non_existent_id"), options - expect(response.status).to eq(404) - end - end - end - - describe "PUT /projects/:id" do - let!(:project) { FactoryGirl.create(:ci_project) } - let!(:project_info) { { default_ref: "develop" } } - - before do - options.merge!(project_info) - end - - it "should update a specific project's information" do - project.gl_project.team << [user, :master] - put ci_api("/projects/#{project.id}"), options - expect(response.status).to eq(200) - expect(json_response["default_ref"]).to eq(project_info[:default_ref]) - end - - it "fails to update a non-existing project" do - put ci_api("/projects/non-existant-id"), options - expect(response.status).to eq(404) - end - - it "non-manager is not authorized" do - put ci_api("/projects/#{project.id}"), options - expect(response.status).to eq(401) - end - end - - describe "POST /projects/:id/runners/:id" do - let(:project) { FactoryGirl.create(:ci_project) } - let(:runner) { FactoryGirl.create(:ci_runner) } - - it "should add the project to the runner" do - project.gl_project.team << [user, :master] - post ci_api("/projects/#{project.id}/runners/#{runner.id}"), options - expect(response.status).to eq(201) - - project.reload - expect(project.runners.first.id).to eq(runner.id) - end - - it "should fail if it tries to link a non-existing project or runner" do - post ci_api("/projects/#{project.id}/runners/non-existing"), options - expect(response.status).to eq(404) - - post ci_api("/projects/non-existing/runners/#{runner.id}"), options - expect(response.status).to eq(404) - end - - it "non-manager is not authorized" do - allow_any_instance_of(User).to receive(:can_manage_project?).and_return(false) - post ci_api("/projects/#{project.id}/runners/#{runner.id}"), options - expect(response.status).to eq(401) - end - end - - describe "DELETE /projects/:id/runners/:id" do - let(:project) { FactoryGirl.create(:ci_project) } - let(:runner) { FactoryGirl.create(:ci_runner) } - - it "should remove the project from the runner" do - project.gl_project.team << [user, :master] - post ci_api("/projects/#{project.id}/runners/#{runner.id}"), options - - expect(project.runners).to be_present - delete ci_api("/projects/#{project.id}/runners/#{runner.id}"), options - expect(response.status).to eq(200) - - project.reload - expect(project.runners).to be_empty - end - - it "non-manager is not authorized" do - delete ci_api("/projects/#{project.id}/runners/#{runner.id}"), options - expect(response.status).to eq(401) - end - end -end diff --git a/spec/requests/ci/api/runners_spec.rb b/spec/requests/ci/api/runners_spec.rb index 11dc089e1f5..ef2f759fdaa 100644 --- a/spec/requests/ci/api/runners_spec.rb +++ b/spec/requests/ci/api/runners_spec.rb @@ -8,29 +8,6 @@ describe Ci::API::API do stub_gitlab_calls end - describe "GET /runners" do - let(:gitlab_url) { GitlabCi.config.gitlab_ci.url } - let(:private_token) { create(:user).private_token } - let(:options) do - { - private_token: private_token, - url: gitlab_url - } - end - - before do - 5.times { FactoryGirl.create(:ci_runner) } - end - - it "should retrieve a list of all runners" do - get ci_api("/runners", nil), options - expect(response.status).to eq(200) - expect(json_response.count).to eq(5) - expect(json_response.last).to have_key("id") - expect(json_response.last).to have_key("token") - end - end - describe "POST /runners/register" do describe "should create a runner if token provided" do before { post ci_api("/runners/register"), token: GitlabCi::REGISTRATION_TOKEN } @@ -53,11 +30,11 @@ describe Ci::API::API do end describe "should create a runner if project token provided" do - let(:project) { FactoryGirl.create(:ci_project) } + let(:project) { FactoryGirl.create(:empty_project) } before { post ci_api("/runners/register"), token: project.token } it { expect(response.status).to eq(201) } - it { expect(project.runners.size).to eq(1) } + it { expect(project.ci_runners.size).to eq(1) } end it "should return 403 error if token is invalid" do diff --git a/spec/requests/ci/api/triggers_spec.rb b/spec/requests/ci/api/triggers_spec.rb index a2b436d5811..cd33a96e1a6 100644 --- a/spec/requests/ci/api/triggers_spec.rb +++ b/spec/requests/ci/api/triggers_spec.rb @@ -5,15 +5,16 @@ describe Ci::API::API do describe 'POST /projects/:project_id/refs/:ref/trigger' do let!(:trigger_token) { 'secure token' } - let!(:gl_project) { FactoryGirl.create(:project) } - let!(:project) { gl_project.ensure_gitlab_ci_project } - let!(:project2) { FactoryGirl.create(:ci_project) } + let!(:project) { FactoryGirl.create(:project) } + let!(:project2) { FactoryGirl.create(:empty_project) } let!(:trigger) { FactoryGirl.create(:ci_trigger, project: project, token: trigger_token) } let(:options) do { token: trigger_token } end + let(:project_ci_id) { create_ci_id(project) } + let(:project2_ci_id) { create_ci_id(project2) } before do stub_ci_commit_to_return_yaml_file @@ -21,7 +22,7 @@ describe Ci::API::API do context 'Handles errors' do it 'should return bad request if token is missing' do - post ci_api("/projects/#{project.id}/refs/master/trigger") + post ci_api("/projects/#{project_ci_id}/refs/master/trigger") expect(response.status).to eq(400) end @@ -31,23 +32,23 @@ describe Ci::API::API do end it 'should return unauthorized if token is for different project' do - post ci_api("/projects/#{project2.id}/refs/master/trigger"), options + post ci_api("/projects/#{project2_ci_id}/refs/master/trigger"), options expect(response.status).to eq(401) end end context 'Have a commit' do - let(:commit) { project.commits.last } + let(:commit) { project.ci_commits.last } it 'should create builds' do - post ci_api("/projects/#{project.id}/refs/master/trigger"), options + post ci_api("/projects/#{project_ci_id}/refs/master/trigger"), options expect(response.status).to eq(201) commit.builds.reload expect(commit.builds.size).to eq(2) end it 'should return bad request with no builds created if there\'s no commit for that ref' do - post ci_api("/projects/#{project.id}/refs/other-branch/trigger"), options + post ci_api("/projects/#{project_ci_id}/refs/other-branch/trigger"), options expect(response.status).to eq(400) expect(json_response['message']).to eq('No builds created') end @@ -58,19 +59,19 @@ describe Ci::API::API do end it 'should validate variables to be a hash' do - post ci_api("/projects/#{project.id}/refs/master/trigger"), options.merge(variables: 'value') + post ci_api("/projects/#{project_ci_id}/refs/master/trigger"), options.merge(variables: 'value') expect(response.status).to eq(400) expect(json_response['message']).to eq('variables needs to be a hash') end it 'should validate variables needs to be a map of key-valued strings' do - post ci_api("/projects/#{project.id}/refs/master/trigger"), options.merge(variables: { key: %w(1 2) }) + post ci_api("/projects/#{project_ci_id}/refs/master/trigger"), options.merge(variables: { key: %w(1 2) }) expect(response.status).to eq(400) expect(json_response['message']).to eq('variables needs to be a map of key-valued strings') end it 'create trigger request with variables' do - post ci_api("/projects/#{project.id}/refs/master/trigger"), options.merge(variables: variables) + post ci_api("/projects/#{project_ci_id}/refs/master/trigger"), options.merge(variables: variables) expect(response.status).to eq(201) commit.builds.reload expect(commit.builds.first.trigger_request.variables).to eq(variables) @@ -78,4 +79,8 @@ describe Ci::API::API do end end end + + def create_ci_id(project) + ActiveRecord::Base.connection.insert("INSERT INTO ci_projects (gitlab_id) VALUES(#{project.id})") + end end diff --git a/spec/services/ci/create_commit_service_spec.rb b/spec/services/ci/create_commit_service_spec.rb index c2fafca2ad2..7e2dcc503e5 100644 --- a/spec/services/ci/create_commit_service_spec.rb +++ b/spec/services/ci/create_commit_service_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' module Ci describe CreateCommitService, services: true do let(:service) { CreateCommitService.new } - let(:project) { FactoryGirl.create(:ci_project) } + let(:project) { FactoryGirl.create(:empty_project) } let(:user) { nil } before do @@ -24,7 +24,7 @@ module Ci it { expect(commit).to be_kind_of(Commit) } it { expect(commit).to be_valid } it { expect(commit).to be_persisted } - it { expect(commit).to eq(project.commits.last) } + it { expect(commit).to eq(project.ci_commits.last) } it { expect(commit.builds.first).to be_kind_of(Build) } end diff --git a/spec/services/ci/create_trigger_request_service_spec.rb b/spec/services/ci/create_trigger_request_service_spec.rb index c80cb58163a..dbdc5370bd8 100644 --- a/spec/services/ci/create_trigger_request_service_spec.rb +++ b/spec/services/ci/create_trigger_request_service_spec.rb @@ -2,8 +2,7 @@ require 'spec_helper' describe Ci::CreateTriggerRequestService, services: true do let(:service) { Ci::CreateTriggerRequestService.new } - let(:gl_project) { create(:project) } - let(:project) { gl_project.ensure_gitlab_ci_project } + let(:project) { create(:project) } let(:trigger) { create(:ci_trigger, project: project) } before do @@ -29,7 +28,7 @@ describe Ci::CreateTriggerRequestService, services: true do before do stub_ci_commit_yaml_file('{}') - FactoryGirl.create :ci_commit, gl_project: gl_project + FactoryGirl.create :ci_commit, project: project end it { expect(subject).to be_nil } diff --git a/spec/services/ci/event_service_spec.rb b/spec/services/ci/event_service_spec.rb deleted file mode 100644 index 32516c75cf3..00000000000 --- a/spec/services/ci/event_service_spec.rb +++ /dev/null @@ -1,34 +0,0 @@ -require 'spec_helper' - -describe Ci::EventService, services: true do - let(:project) { FactoryGirl.create :ci_project } - let(:user) { double(username: "root", id: 1) } - - before do - Event.destroy_all - end - - describe :remove_project do - it "creates event" do - Ci::EventService.new.remove_project(user, project) - - expect(Ci::Event.admin.last.description).to eq("Project \"#{project.name_with_namespace}\" has been removed by root") - end - end - - describe :create_project do - it "creates event" do - Ci::EventService.new.create_project(user, project) - - expect(Ci::Event.admin.last.description).to eq("Project \"#{project.name_with_namespace}\" has been created by root") - end - end - - describe :change_project_settings do - it "creates event" do - Ci::EventService.new.change_project_settings(user, project) - - expect(Ci::Event.last.description).to eq("User \"root\" updated projects settings") - end - end -end diff --git a/spec/services/ci/image_for_build_service_spec.rb b/spec/services/ci/image_for_build_service_spec.rb index b43cabb4ee4..870861ad20a 100644 --- a/spec/services/ci/image_for_build_service_spec.rb +++ b/spec/services/ci/image_for_build_service_spec.rb @@ -3,16 +3,16 @@ require 'spec_helper' module Ci describe ImageForBuildService, services: true do let(:service) { ImageForBuildService.new } - let(:project) { FactoryGirl.create(:ci_project) } - let(:gl_project) { FactoryGirl.create(:project, gitlab_ci_project: project) } - let(:commit_sha) { gl_project.commit('master').sha } - let(:commit) { gl_project.ensure_ci_commit(commit_sha) } + let(:project) { FactoryGirl.create(:empty_project) } + let(:commit_sha) { '01234567890123456789' } + let(:commit) { project.ensure_ci_commit(commit_sha) } let(:build) { FactoryGirl.create(:ci_build, commit: commit) } describe :execute do before { build } context 'branch name' do + before { allow(project).to receive(:commit).and_return(OpenStruct.new(sha: commit_sha)) } before { build.run! } let(:image) { service.execute(project, ref: 'master') } diff --git a/spec/services/ci/register_build_service_spec.rb b/spec/services/ci/register_build_service_spec.rb index 379e07982fb..e81f9e757ac 100644 --- a/spec/services/ci/register_build_service_spec.rb +++ b/spec/services/ci/register_build_service_spec.rb @@ -3,14 +3,14 @@ require 'spec_helper' module Ci describe RegisterBuildService, services: true do let!(:service) { RegisterBuildService.new } - let!(:gl_project) { FactoryGirl.create :empty_project } - let!(:commit) { FactoryGirl.create :ci_commit, gl_project: gl_project } + let!(:project) { FactoryGirl.create :empty_project, shared_runners_enabled: false } + let!(:commit) { FactoryGirl.create :ci_commit, project: project } let!(:pending_build) { FactoryGirl.create :ci_build, commit: commit } let!(:shared_runner) { FactoryGirl.create(:ci_runner, is_shared: true) } let!(:specific_runner) { FactoryGirl.create(:ci_runner, is_shared: false) } before do - specific_runner.assign_to(gl_project.ensure_gitlab_ci_project) + specific_runner.assign_to(project) end describe :execute do @@ -47,7 +47,7 @@ module Ci context 'allow shared runners' do before do - gl_project.gitlab_ci_project.update(shared_runners_enabled: true) + project.update(shared_runners_enabled: true) end context 'shared runner' do @@ -71,7 +71,7 @@ module Ci context 'disallow shared runners' do before do - gl_project.gitlab_ci_project.update(shared_runners_enabled: false) + project.update(shared_runners_enabled: false) end context 'shared runner' do |