Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/projects/variables_controller_spec.rb2
-rw-r--r--spec/factories/ci/runner_projects.rb2
-rw-r--r--spec/features/admin/admin_settings_spec.rb3
-rw-r--r--spec/features/projects/import_export/test_project_export.tar.gzbin681799 -> 679892 bytes
-rw-r--r--spec/features/projects/services/slack_service_spec.rb4
-rw-r--r--spec/lib/gitlab/import_export/all_models.yml1
-rw-r--r--spec/lib/gitlab/import_export/project.json51
-rw-r--r--spec/lib/gitlab/import_export/project_tree_restorer_spec.rb19
-rw-r--r--spec/lib/gitlab/import_export/safe_model_attributes.yml4
-rw-r--r--spec/mailers/emails/builds_spec.rb64
-rw-r--r--spec/migrations/migrate_build_events_to_pipeline_events_spec.rb74
-rw-r--r--spec/models/ci/build_spec.rb4
-rw-r--r--spec/models/ci/variable_spec.rb2
-rw-r--r--spec/models/project_services/builds_email_service_spec.rb111
-rw-r--r--spec/models/project_services/chat_message/build_message_spec.rb77
-rw-r--r--spec/models/project_services/hipchat_service_spec.rb42
-rw-r--r--spec/models/project_spec.rb3
-rw-r--r--spec/services/ci/retry_build_service_spec.rb2
-rw-r--r--spec/workers/build_email_worker_spec.rb36
19 files changed, 133 insertions, 368 deletions
diff --git a/spec/controllers/projects/variables_controller_spec.rb b/spec/controllers/projects/variables_controller_spec.rb
index e3f3b4fe8eb..1ecfe48475c 100644
--- a/spec/controllers/projects/variables_controller_spec.rb
+++ b/spec/controllers/projects/variables_controller_spec.rb
@@ -35,7 +35,7 @@ describe Projects::VariablesController do
context 'updating a variable with valid characters' do
before do
- variable.gl_project_id = project.id
+ variable.project_id = project.id
project.variables << variable
end
diff --git a/spec/factories/ci/runner_projects.rb b/spec/factories/ci/runner_projects.rb
index 3372e5ab685..6712dd5d82e 100644
--- a/spec/factories/ci/runner_projects.rb
+++ b/spec/factories/ci/runner_projects.rb
@@ -1,6 +1,6 @@
FactoryGirl.define do
factory :ci_runner_project, class: Ci::RunnerProject do
runner_id 1
- gl_project_id 1
+ project_id 1
end
end
diff --git a/spec/features/admin/admin_settings_spec.rb b/spec/features/admin/admin_settings_spec.rb
index de42ab81fac..b4095095887 100644
--- a/spec/features/admin/admin_settings_spec.rb
+++ b/spec/features/admin/admin_settings_spec.rb
@@ -26,7 +26,7 @@ feature 'Admin updates settings', feature: true do
fill_in 'Webhook', with: 'http://localhost'
fill_in 'Username', with: 'test_user'
fill_in 'service_push_channel', with: '#test_channel'
- page.check('Notify only broken builds')
+ page.check('Notify only broken pipelines')
check_all_events
click_on 'Save'
@@ -50,7 +50,6 @@ feature 'Admin updates settings', feature: true do
page.check('Note')
page.check('Issue')
page.check('Merge request')
- page.check('Build')
page.check('Pipeline')
end
end
diff --git a/spec/features/projects/import_export/test_project_export.tar.gz b/spec/features/projects/import_export/test_project_export.tar.gz
index 20cdfbae24f..399c1d478c5 100644
--- a/spec/features/projects/import_export/test_project_export.tar.gz
+++ b/spec/features/projects/import_export/test_project_export.tar.gz
Binary files differ
diff --git a/spec/features/projects/services/slack_service_spec.rb b/spec/features/projects/services/slack_service_spec.rb
index 16541f51d98..c0a4a1e4bf5 100644
--- a/spec/features/projects/services/slack_service_spec.rb
+++ b/spec/features/projects/services/slack_service_spec.rb
@@ -7,7 +7,7 @@ feature 'Projects > Slack service > Setup events', feature: true do
background do
service.fields
- service.update_attributes(push_channel: 1, issue_channel: 2, merge_request_channel: 3, note_channel: 4, tag_push_channel: 5, build_channel: 6, wiki_page_channel: 7)
+ service.update_attributes(push_channel: 1, issue_channel: 2, merge_request_channel: 3, note_channel: 4, tag_push_channel: 5, pipeline_channel: 6, wiki_page_channel: 7)
project.team << [user, :master]
login_as(user)
end
@@ -20,7 +20,7 @@ feature 'Projects > Slack service > Setup events', feature: true do
expect(page.find_field("service_merge_request_channel").value).to have_content '3'
expect(page.find_field("service_note_channel").value).to have_content '4'
expect(page.find_field("service_tag_push_channel").value).to have_content '5'
- expect(page.find_field("service_build_channel").value).to have_content '6'
+ expect(page.find_field("service_pipeline_channel").value).to have_content '6'
expect(page.find_field("service_wiki_page_channel").value).to have_content '7'
end
end
diff --git a/spec/lib/gitlab/import_export/all_models.yml b/spec/lib/gitlab/import_export/all_models.yml
index e47956a365f..ddeb71730e7 100644
--- a/spec/lib/gitlab/import_export/all_models.yml
+++ b/spec/lib/gitlab/import_export/all_models.yml
@@ -130,7 +130,6 @@ project:
- campfire_service
- drone_ci_service
- emails_on_push_service
-- builds_email_service
- pipelines_email_service
- mattermost_slash_commands_service
- slack_slash_commands_service
diff --git a/spec/lib/gitlab/import_export/project.json b/spec/lib/gitlab/import_export/project.json
index c3d5c451a3c..d9b67426818 100644
--- a/spec/lib/gitlab/import_export/project.json
+++ b/spec/lib/gitlab/import_export/project.json
@@ -6507,7 +6507,6 @@
"tag": null,
"yaml_errors": null,
"committed_at": null,
- "gl_project_id": 5,
"status": "failed",
"started_at": null,
"finished_at": null,
@@ -6565,7 +6564,6 @@
"artifacts_file": {
"url": null
},
- "gl_project_id": 5,
"artifacts_metadata": {
"url": null
},
@@ -6603,7 +6601,6 @@
"artifacts_file": {
"url": "/Users/Test/Test/gitlab-development-kit/gitlab/shared/artifacts/2016_03/5/72/p5_build_artifacts.zip"
},
- "gl_project_id": 5,
"artifacts_metadata": {
"url": "/Users/Test/Test/gitlab-development-kit/gitlab/shared/artifacts/2016_03/5/72/p5_build_artifacts_metadata.gz"
},
@@ -6624,7 +6621,6 @@
"tag": null,
"yaml_errors": null,
"committed_at": null,
- "gl_project_id": 5,
"status": "failed",
"started_at": null,
"finished_at": null,
@@ -6659,7 +6655,6 @@
"artifacts_file": {
"url": "/Users/Test/Test/gitlab-development-kit/gitlab/shared/artifacts/2016_03/5/74/p5_build_artifacts.zip"
},
- "gl_project_id": 5,
"artifacts_metadata": {
"url": "/Users/Test/Test/gitlab-development-kit/gitlab/shared/artifacts/2016_03/5/74/p5_build_artifacts_metadata.gz"
},
@@ -6695,7 +6690,6 @@
"artifacts_file": {
"url": null
},
- "gl_project_id": 5,
"artifacts_metadata": {
"url": null
},
@@ -6716,7 +6710,6 @@
"tag": null,
"yaml_errors": null,
"committed_at": null,
- "gl_project_id": 5,
"status": "failed",
"started_at": null,
"finished_at": null,
@@ -6751,7 +6744,6 @@
"artifacts_file": {
"url": "/Users/Test/Test/gitlab-development-kit/gitlab/shared/artifacts/2016_03/5/76/p5_build_artifacts.zip"
},
- "gl_project_id": 5,
"artifacts_metadata": {
"url": "/Users/Test/Test/gitlab-development-kit/gitlab/shared/artifacts/2016_03/5/76/p5_build_artifacts_metadata.gz"
},
@@ -6787,7 +6779,6 @@
"artifacts_file": {
"url": "/Users/Test/Test/gitlab-development-kit/gitlab/shared/artifacts/2016_03/5/75/p5_build_artifacts.zip"
},
- "gl_project_id": 5,
"artifacts_metadata": {
"url": "/Users/Test/Test/gitlab-development-kit/gitlab/shared/artifacts/2016_03/5/75/p5_build_artifacts_metadata.gz"
},
@@ -6808,7 +6799,6 @@
"tag": null,
"yaml_errors": null,
"committed_at": null,
- "gl_project_id": 5,
"status": "failed",
"started_at": null,
"finished_at": null,
@@ -6843,7 +6833,6 @@
"artifacts_file": {
"url": "/Users/Test/Test/gitlab-development-kit/gitlab/shared/artifacts/2016_03/5/78/p5_build_artifacts.zip"
},
- "gl_project_id": 5,
"artifacts_metadata": {
"url": "/Users/Test/Test/gitlab-development-kit/gitlab/shared/artifacts/2016_03/5/78/p5_build_artifacts_metadata.gz"
},
@@ -6879,7 +6868,6 @@
"artifacts_file": {
"url": "/Users/Test/Test/gitlab-development-kit/gitlab/shared/artifacts/2016_03/5/77/p5_build_artifacts.zip"
},
- "gl_project_id": 5,
"artifacts_metadata": {
"url": "/Users/Test/Test/gitlab-development-kit/gitlab/shared/artifacts/2016_03/5/77/p5_build_artifacts_metadata.gz"
},
@@ -6900,7 +6888,6 @@
"tag": null,
"yaml_errors": null,
"committed_at": null,
- "gl_project_id": 5,
"status": "failed",
"started_at": null,
"finished_at": null,
@@ -6935,7 +6922,6 @@
"artifacts_file": {
"url": null
},
- "gl_project_id": 5,
"artifacts_metadata": {
"url": null
},
@@ -6971,7 +6957,6 @@
"artifacts_file": {
"url": "/Users/Test/Test/gitlab-development-kit/gitlab/shared/artifacts/2016_03/5/80/p5_build_artifacts.zip"
},
- "gl_project_id": 5,
"artifacts_metadata": {
"url": "/Users/Test/Test/gitlab-development-kit/gitlab/shared/artifacts/2016_03/5/80/p5_build_artifacts_metadata.gz"
},
@@ -6985,11 +6970,10 @@
{
"id": 123,
"token": "cdbfasdf44a5958c83654733449e585",
- "project_id": null,
+ "project_id": 5,
"deleted_at": null,
"created_at": "2017-01-16T15:25:28.637Z",
- "updated_at": "2017-01-16T15:25:28.637Z",
- "gl_project_id": 123
+ "updated_at": "2017-01-16T15:25:28.637Z"
}
],
"deploy_keys": [
@@ -7047,7 +7031,7 @@
"updated_at": "2016-06-14T15:01:51.303Z",
"active": false,
"properties": {
- "notify_only_broken_builds": true
+ "notify_only_broken_pipelines": true
},
"template": false,
"push_events": true,
@@ -7055,7 +7039,7 @@
"merge_requests_events": true,
"tag_push_events": true,
"note_events": true,
- "build_events": true,
+ "pipeline_events": true,
"category": "common",
"default": false,
"wiki_page_events": true
@@ -7174,7 +7158,7 @@
"updated_at": "2016-06-14T15:01:51.219Z",
"active": false,
"properties": {
- "notify_only_broken_builds": true
+ "notify_only_broken_pipelines": true
},
"template": false,
"push_events": true,
@@ -7182,7 +7166,7 @@
"merge_requests_events": true,
"tag_push_events": true,
"note_events": true,
- "build_events": true,
+ "pipeline_events": true,
"category": "common",
"default": false,
"wiki_page_events": true
@@ -7335,27 +7319,6 @@
"wiki_page_events": true
},
{
- "id": 85,
- "title": "Builds emails",
- "project_id": 5,
- "created_at": "2016-06-14T15:01:51.090Z",
- "updated_at": "2016-06-14T15:01:51.090Z",
- "active": false,
- "properties": {
- "notify_only_broken_builds": true
- },
- "template": false,
- "push_events": true,
- "issues_events": true,
- "merge_requests_events": true,
- "tag_push_events": true,
- "note_events": true,
- "build_events": true,
- "category": "common",
- "default": false,
- "wiki_page_events": true
- },
- {
"id": 84,
"title": "Buildkite",
"project_id": 5,
@@ -7503,4 +7466,4 @@
"updated_at": "2016-09-23T11:58:28.000Z",
"wiki_access_level": 20
}
-} \ No newline at end of file
+}
diff --git a/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb b/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb
index f4a21c24fa1..c36f12dbd82 100644
--- a/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb
+++ b/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb
@@ -129,6 +129,25 @@ describe Gitlab::ImportExport::ProjectTreeRestorer, services: true do
expect(Ci::Build.where(token: 'abcd')).to be_empty
end
end
+
+ context 'has restored the correct number of records' do
+ it 'has the correct number of merge requests' do
+ expect(@project.merge_requests.size).to eq(9)
+ end
+
+ it 'has the correct number of triggers' do
+ expect(@project.triggers.size).to eq(1)
+ end
+
+ it 'has the correct number of pipelines and statuses' do
+ expect(@project.pipelines.size).to eq(5)
+
+ @project.pipelines.zip([2, 2, 2, 2, 2])
+ .each do |(pipeline, expected_status_size)|
+ expect(pipeline.statuses.size).to eq(expected_status_size)
+ end
+ end
+ end
end
end
diff --git a/spec/lib/gitlab/import_export/safe_model_attributes.yml b/spec/lib/gitlab/import_export/safe_model_attributes.yml
index c718e792461..042b7b0a20d 100644
--- a/spec/lib/gitlab/import_export/safe_model_attributes.yml
+++ b/spec/lib/gitlab/import_export/safe_model_attributes.yml
@@ -176,7 +176,6 @@ Ci::Pipeline:
- tag
- yaml_errors
- committed_at
-- gl_project_id
- status
- started_at
- finished_at
@@ -211,7 +210,6 @@ CommitStatus:
- target_url
- description
- artifacts_file
-- gl_project_id
- artifacts_metadata
- erased_by_id
- erased_at
@@ -232,7 +230,6 @@ Ci::Variable:
- encrypted_value
- encrypted_value_salt
- encrypted_value_iv
-- gl_project_id
Ci::Trigger:
- id
- token
@@ -240,7 +237,6 @@ Ci::Trigger:
- deleted_at
- created_at
- updated_at
-- gl_project_id
- owner_id
- description
DeployKey:
diff --git a/spec/mailers/emails/builds_spec.rb b/spec/mailers/emails/builds_spec.rb
deleted file mode 100644
index d968096783c..00000000000
--- a/spec/mailers/emails/builds_spec.rb
+++ /dev/null
@@ -1,64 +0,0 @@
-require 'spec_helper'
-require 'email_spec'
-
-describe Notify do
- include EmailSpec::Matchers
-
- include_context 'gitlab email notification'
-
- describe 'build notification email' do
- let(:build) { create(:ci_build) }
- let(:project) { build.project }
-
- shared_examples 'build email' do
- it 'contains name of project' do
- is_expected.to have_body_text build.project_name
- end
-
- it 'contains link to project' do
- is_expected.to have_body_text namespace_project_path(project.namespace, project)
- end
- end
-
- shared_examples 'an email with X-GitLab headers containing build details' do
- it 'has X-GitLab-Build* headers' do
- is_expected.to have_header 'X-GitLab-Build-Id', /#{build.id}/
- is_expected.to have_header 'X-GitLab-Build-Ref', /#{build.ref}/
- end
- end
-
- describe 'build success' do
- subject { Notify.build_success_email(build.id, 'wow@example.com') }
- before { build.success }
-
- it_behaves_like 'build email'
- it_behaves_like 'an email with X-GitLab headers containing build details'
- it_behaves_like 'an email with X-GitLab headers containing project details'
-
- it 'has header indicating build status' do
- is_expected.to have_header 'X-GitLab-Build-Status', 'success'
- end
-
- it 'has the correct subject' do
- is_expected.to have_subject /Build success for/
- end
- end
-
- describe 'build fail' do
- subject { Notify.build_fail_email(build.id, 'wow@example.com') }
- before { build.drop }
-
- it_behaves_like 'build email'
- it_behaves_like 'an email with X-GitLab headers containing build details'
- it_behaves_like 'an email with X-GitLab headers containing project details'
-
- it 'has header indicating build status' do
- is_expected.to have_header 'X-GitLab-Build-Status', 'failed'
- end
-
- it 'has the correct subject' do
- is_expected.to have_subject /Build failed for/
- end
- end
- end
-end
diff --git a/spec/migrations/migrate_build_events_to_pipeline_events_spec.rb b/spec/migrations/migrate_build_events_to_pipeline_events_spec.rb
new file mode 100644
index 00000000000..57eb03e3c80
--- /dev/null
+++ b/spec/migrations/migrate_build_events_to_pipeline_events_spec.rb
@@ -0,0 +1,74 @@
+require 'spec_helper'
+require Rails.root.join('db', 'post_migrate', '20170301205640_migrate_build_events_to_pipeline_events.rb')
+
+# This migration uses multiple threads, and thus different transactions. This
+# means data created in this spec may not be visible to some threads. To work
+# around this we use the TRUNCATE cleaning strategy.
+describe MigrateBuildEventsToPipelineEvents, truncate: true do
+ let(:migration) { described_class.new }
+ let(:project_with_pipeline_service) { create(:empty_project) }
+ let(:project_with_build_service) { create(:empty_project) }
+
+ before do
+ ActiveRecord::Base.connection.execute <<-SQL
+ INSERT INTO services (properties, build_events, pipeline_events, type)
+ VALUES
+ ('{"notify_only_broken_builds":true}', true, false, 'SlackService')
+ , ('{"notify_only_broken_builds":true}', true, false, 'MattermostService')
+ , ('{"notify_only_broken_builds":true}', true, false, 'HipchatService')
+ ;
+ SQL
+
+ ActiveRecord::Base.connection.execute <<-SQL
+ INSERT INTO services
+ (properties, build_events, pipeline_events, type, project_id)
+ VALUES
+ ('{"notify_only_broken_builds":true}', true, false,
+ 'BuildsEmailService', #{project_with_pipeline_service.id})
+ , ('{"notify_only_broken_pipelines":true}', false, true,
+ 'PipelinesEmailService', #{project_with_pipeline_service.id})
+ , ('{"notify_only_broken_builds":true}', true, false,
+ 'BuildsEmailService', #{project_with_build_service.id})
+ ;
+ SQL
+ end
+
+ describe '#up' do
+ before do
+ silence_migration = Module.new do
+ # rubocop:disable Rails/Delegate
+ def execute(query)
+ connection.execute(query)
+ end
+ end
+
+ migration.extend(silence_migration)
+ migration.up
+ end
+
+ it 'migrates chat service properly' do
+ [SlackService, MattermostService, HipchatService].each do |service|
+ expect(service.count).to eq(1)
+
+ verify_service_record(service.first)
+ end
+ end
+
+ it 'migrates pipelines email service only if it has none before' do
+ Project.find_each do |project|
+ pipeline_service_count =
+ project.services.where(type: 'PipelinesEmailService').count
+
+ expect(pipeline_service_count).to eq(1)
+
+ verify_service_record(project.pipelines_email_service)
+ end
+ end
+
+ def verify_service_record(service)
+ expect(service.notify_only_broken_pipelines).to be(true)
+ expect(service.build_events).to be(false)
+ expect(service.pipeline_events).to be(true)
+ end
+ end
+end
diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb
index fd6ea2d6722..8dbcf50ee0c 100644
--- a/spec/models/ci/build_spec.rb
+++ b/spec/models/ci/build_spec.rb
@@ -795,8 +795,8 @@ describe Ci::Build, :models do
describe '#merge_request' do
def create_mr(build, pipeline, factory: :merge_request, created_at: Time.now)
- create(factory, source_project_id: pipeline.gl_project_id,
- target_project_id: pipeline.gl_project_id,
+ create(factory, source_project: pipeline.project,
+ target_project: pipeline.project,
source_branch: build.ref,
created_at: created_at)
end
diff --git a/spec/models/ci/variable_spec.rb b/spec/models/ci/variable_spec.rb
index bee9f714849..048d25869bc 100644
--- a/spec/models/ci/variable_spec.rb
+++ b/spec/models/ci/variable_spec.rb
@@ -6,7 +6,7 @@ describe Ci::Variable, models: true do
let(:secret_value) { 'secret' }
it { is_expected.to validate_presence_of(:key) }
- it { is_expected.to validate_uniqueness_of(:key).scoped_to(:gl_project_id) }
+ it { is_expected.to validate_uniqueness_of(:key).scoped_to(:project_id) }
it { is_expected.to validate_length_of(:key).is_at_most(255) }
it { is_expected.to allow_value('foo').for(:key) }
it { is_expected.not_to allow_value('foo bar').for(:key) }
diff --git a/spec/models/project_services/builds_email_service_spec.rb b/spec/models/project_services/builds_email_service_spec.rb
deleted file mode 100644
index 0194f9e2563..00000000000
--- a/spec/models/project_services/builds_email_service_spec.rb
+++ /dev/null
@@ -1,111 +0,0 @@
-require 'spec_helper'
-
-describe BuildsEmailService do
- let(:data) do
- Gitlab::DataBuilder::Build.build(create(:ci_build))
- end
-
- describe 'Validations' do
- context 'when service is active' do
- before { subject.active = true }
-
- it { is_expected.to validate_presence_of(:recipients) }
-
- context 'when pusher is added' do
- before { subject.add_pusher = true }
-
- it { is_expected.not_to validate_presence_of(:recipients) }
- end
- end
-
- context 'when service is inactive' do
- before { subject.active = false }
-
- it { is_expected.not_to validate_presence_of(:recipients) }
- end
- end
-
- describe '#test_data' do
- let(:build) { create(:ci_build) }
- let(:project) { build.project }
- let(:user) { create(:user) }
-
- before { project.team << [user, :developer] }
-
- it 'builds test data' do
- data = subject.test_data(project)
-
- expect(data[:object_kind]).to eq("build")
- end
- end
-
- describe '#test' do
- it 'sends email' do
- data = Gitlab::DataBuilder::Build.build(create(:ci_build))
- subject.recipients = 'test@gitlab.com'
-
- expect(BuildEmailWorker).to receive(:perform_async)
-
- subject.test(data)
- end
-
- context 'notify only failed builds is true' do
- it 'sends email' do
- data = Gitlab::DataBuilder::Build.build(create(:ci_build))
- data[:build_status] = "success"
- subject.recipients = 'test@gitlab.com'
-
- expect(subject).not_to receive(:notify_only_broken_builds)
- expect(BuildEmailWorker).to receive(:perform_async)
-
- subject.test(data)
- end
- end
- end
-
- describe '#execute' do
- it 'sends email' do
- subject.recipients = 'test@gitlab.com'
- data[:build_status] = 'failed'
-
- expect(BuildEmailWorker).to receive(:perform_async)
-
- subject.execute(data)
- end
-
- it 'does not send email with succeeded build and notify_only_broken_builds on' do
- expect(subject).to receive(:notify_only_broken_builds).and_return(true)
- data[:build_status] = 'success'
-
- expect(BuildEmailWorker).not_to receive(:perform_async)
-
- subject.execute(data)
- end
-
- it 'does not send email with failed build and build_allow_failure is true' do
- data[:build_status] = 'failed'
- data[:build_allow_failure] = true
-
- expect(BuildEmailWorker).not_to receive(:perform_async)
-
- subject.execute(data)
- end
-
- it 'does not send email with unknown build status' do
- data[:build_status] = 'foo'
-
- expect(BuildEmailWorker).not_to receive(:perform_async)
-
- subject.execute(data)
- end
-
- it 'does not send email when recipients list is empty' do
- subject.recipients = ' ,, '
- data[:build_status] = 'failed'
-
- expect(BuildEmailWorker).not_to receive(:perform_async)
-
- subject.execute(data)
- end
- end
-end
diff --git a/spec/models/project_services/chat_message/build_message_spec.rb b/spec/models/project_services/chat_message/build_message_spec.rb
deleted file mode 100644
index 3bd7ec18ae0..00000000000
--- a/spec/models/project_services/chat_message/build_message_spec.rb
+++ /dev/null
@@ -1,77 +0,0 @@
-require 'spec_helper'
-
-describe ChatMessage::BuildMessage do
- subject { described_class.new(args) }
-
- let(:args) do
- {
- sha: '97de212e80737a608d939f648d959671fb0a0142',
- ref: 'develop',
- tag: false,
-
- project_name: 'project_name',
- project_url: 'http://example.gitlab.com',
- build_id: 1,
- build_name: build_name,
- build_stage: stage,
-
- commit: {
- status: status,
- author_name: 'hacker',
- author_url: 'http://example.gitlab.com/hacker',
- duration: duration,
- },
- }
- end
-
- let(:message) { build_message }
- let(:stage) { 'test' }
- let(:status) { 'success' }
- let(:build_name) { 'rspec' }
- let(:duration) { 10 }
-
- context 'build succeeded' do
- let(:status) { 'success' }
- let(:color) { 'good' }
- let(:message) { build_message('passed') }
-
- it 'returns a message with information about succeeded build' do
- expect(subject.pretext).to be_empty
- expect(subject.fallback).to eq(message)
- expect(subject.attachments).to eq([text: message, color: color])
- end
- end
-
- context 'build failed' do
- let(:status) { 'failed' }
- let(:color) { 'danger' }
-
- it 'returns a message with information about failed build' do
- expect(subject.pretext).to be_empty
- expect(subject.fallback).to eq(message)
- expect(subject.attachments).to eq([text: message, color: color])
- end
- end
-
- it 'returns a message with information on build' do
- expect(subject.fallback).to include("on build <http://example.gitlab.com/builds/1|#{build_name}>")
- end
-
- it 'returns a message with stage name' do
- expect(subject.fallback).to include("of stage #{stage}")
- end
-
- it 'returns a message with link to author' do
- expect(subject.fallback).to include("by <http://example.gitlab.com/hacker|hacker>")
- end
-
- def build_message(status_text = status, stage_text = stage, build_text = build_name)
- "<http://example.gitlab.com|project_name>:" \
- " Commit <http://example.gitlab.com/commit/" \
- "97de212e80737a608d939f648d959671fb0a0142/builds|97de212e>" \
- " of <http://example.gitlab.com/commits/develop|develop> branch" \
- " by <http://example.gitlab.com/hacker|hacker> #{status_text}" \
- " on build <http://example.gitlab.com/builds/1|#{build_text}>" \
- " of stage #{stage_text} in #{duration} #{'second'.pluralize(duration)}"
- end
-end
diff --git a/spec/models/project_services/hipchat_service_spec.rb b/spec/models/project_services/hipchat_service_spec.rb
index bf422ac7ce1..1200ae7eb22 100644
--- a/spec/models/project_services/hipchat_service_spec.rb
+++ b/spec/models/project_services/hipchat_service_spec.rb
@@ -280,13 +280,14 @@ describe HipchatService, models: true do
end
end
- context 'build events' do
- let(:pipeline) { create(:ci_empty_pipeline) }
- let(:build) { create(:ci_build, pipeline: pipeline) }
- let(:data) { Gitlab::DataBuilder::Build.build(build.reload) }
+ context 'pipeline events' do
+ let(:pipeline) { create(:ci_empty_pipeline, user: create(:user)) }
+ let(:data) { Gitlab::DataBuilder::Pipeline.build(pipeline) }
context 'for failed' do
- before { build.drop }
+ before do
+ pipeline.drop
+ end
it "calls Hipchat API" do
hipchat.execute(data)
@@ -295,35 +296,36 @@ describe HipchatService, models: true do
end
it "creates a build message" do
- message = hipchat.send(:create_build_message, data)
+ message = hipchat.__send__(:create_pipeline_message, data)
project_url = project.web_url
project_name = project.name_with_namespace.gsub(/\s/, '')
- sha = data[:sha]
- ref = data[:ref]
- ref_type = data[:tag] ? 'tag' : 'branch'
- duration = data[:commit][:duration]
+ pipeline_attributes = data[:object_attributes]
+ ref = pipeline_attributes[:ref]
+ ref_type = pipeline_attributes[:tag] ? 'tag' : 'branch'
+ duration = pipeline_attributes[:duration]
+ user_name = data[:user][:name]
expect(message).to eq("<a href=\"#{project_url}\">#{project_name}</a>: " \
- "Commit <a href=\"#{project_url}/commit/#{sha}/builds\">#{Commit.truncate_sha(sha)}</a> " \
+ "Pipeline <a href=\"#{project_url}/pipelines/#{pipeline.id}\">##{pipeline.id}</a> " \
"of <a href=\"#{project_url}/commits/#{ref}\">#{ref}</a> #{ref_type} " \
- "by #{data[:commit][:author_name]} failed in #{duration} second(s)")
+ "by #{user_name} failed in #{duration} second(s)")
end
end
context 'for succeeded' do
before do
- build.success
+ pipeline.succeed
end
it "calls Hipchat API" do
- hipchat.notify_only_broken_builds = false
+ hipchat.notify_only_broken_pipelines = false
hipchat.execute(data)
expect(WebMock).to have_requested(:post, api_url).once
end
it "notifies only broken" do
- hipchat.notify_only_broken_builds = true
+ hipchat.notify_only_broken_pipelines = true
hipchat.execute(data)
expect(WebMock).not_to have_requested(:post, api_url).once
end
@@ -349,17 +351,19 @@ describe HipchatService, models: true do
context 'with a successful build' do
it 'uses the green color' do
- build_data = { object_kind: 'build', commit: { status: 'success' } }
+ data = { object_kind: 'pipeline',
+ object_attributes: { status: 'success' } }
- expect(hipchat.__send__(:message_options, build_data)).to eq({ notify: false, color: 'green' })
+ expect(hipchat.__send__(:message_options, data)).to eq({ notify: false, color: 'green' })
end
end
context 'with a failed build' do
it 'uses the red color' do
- build_data = { object_kind: 'build', commit: { status: 'failed' } }
+ data = { object_kind: 'pipeline',
+ object_attributes: { status: 'failed' } }
- expect(hipchat.__send__(:message_options, build_data)).to eq({ notify: false, color: 'red' })
+ expect(hipchat.__send__(:message_options, data)).to eq({ notify: false, color: 'red' })
end
end
end
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index ff1defcd32d..618ce2b6d53 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -29,8 +29,7 @@ describe Project, models: true do
it { is_expected.to have_one(:campfire_service).dependent(:destroy) }
it { is_expected.to have_one(:drone_ci_service).dependent(:destroy) }
it { is_expected.to have_one(:emails_on_push_service).dependent(:destroy) }
- it { is_expected.to have_one(:builds_email_service).dependent(:destroy) }
- it { is_expected.to have_one(:emails_on_push_service).dependent(:destroy) }
+ it { is_expected.to have_one(:pipelines_email_service).dependent(:destroy) }
it { is_expected.to have_one(:irker_service).dependent(:destroy) }
it { is_expected.to have_one(:pivotaltracker_service).dependent(:destroy) }
it { is_expected.to have_one(:hipchat_service).dependent(:destroy) }
diff --git a/spec/services/ci/retry_build_service_spec.rb b/spec/services/ci/retry_build_service_spec.rb
index 65af4e13118..8567817147b 100644
--- a/spec/services/ci/retry_build_service_spec.rb
+++ b/spec/services/ci/retry_build_service_spec.rb
@@ -19,7 +19,7 @@ describe Ci::RetryBuildService, :services do
erased_at].freeze
IGNORE_ACCESSORS =
- %i[type lock_version target_url gl_project_id deploy job_id base_tags
+ %i[type lock_version target_url base_tags
commit_id deployments erased_by_id last_deployment project_id
runner_id tag_taggings taggings tags trigger_request_id
user_id].freeze
diff --git a/spec/workers/build_email_worker_spec.rb b/spec/workers/build_email_worker_spec.rb
deleted file mode 100644
index 542e674c150..00000000000
--- a/spec/workers/build_email_worker_spec.rb
+++ /dev/null
@@ -1,36 +0,0 @@
-require 'spec_helper'
-
-describe BuildEmailWorker do
- include EmailHelpers
- include RepoHelpers
-
- let(:build) { create(:ci_build) }
- let(:user) { create(:user) }
- let(:data) { Gitlab::DataBuilder::Build.build(build) }
-
- subject { BuildEmailWorker.new }
-
- before do
- allow(build).to receive(:execute_hooks).and_return(false)
- build.success
- end
-
- describe "#perform" do
- it "sends mail" do
- subject.perform(build.id, [user.email], data.stringify_keys)
-
- email = ActionMailer::Base.deliveries.last
- expect(email.subject).to include('Build success for')
- expect(email.to).to eq([user.email])
- end
-
- it "gracefully handles an input SMTP error" do
- reset_delivered_emails!
- allow(Notify).to receive(:build_success_email).and_raise(Net::SMTPFatalError)
-
- subject.perform(build.id, [user.email], data.stringify_keys)
-
- expect(ActionMailer::Base.deliveries.count).to eq(0)
- end
- end
-end