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
diff options
context:
space:
mode:
Diffstat (limited to 'spec/support/shared_examples/models/chat_integration_shared_examples.rb')
-rw-r--r--spec/support/shared_examples/models/chat_integration_shared_examples.rb51
1 files changed, 28 insertions, 23 deletions
diff --git a/spec/support/shared_examples/models/chat_integration_shared_examples.rb b/spec/support/shared_examples/models/chat_integration_shared_examples.rb
index fb08784f34f..6cfeeabc952 100644
--- a/spec/support/shared_examples/models/chat_integration_shared_examples.rb
+++ b/spec/support/shared_examples/models/chat_integration_shared_examples.rb
@@ -32,9 +32,11 @@ RSpec.shared_examples "chat integration" do |integration_name|
end
describe "#execute" do
- let(:user) { create(:user) }
- let(:project) { create(:project, :repository) }
+ let_it_be(:user) { create(:user) }
+ let_it_be_with_reload(:project) { create(:project, :repository) }
+
let(:webhook_url) { "https://example.gitlab.com/" }
+ let(:webhook_url_regex) { /\A#{webhook_url}.*/ }
before do
allow(subject).to receive_messages(
@@ -44,7 +46,7 @@ RSpec.shared_examples "chat integration" do |integration_name|
webhook: webhook_url
)
- WebMock.stub_request(:post, webhook_url)
+ WebMock.stub_request(:post, webhook_url_regex)
end
shared_examples "triggered #{integration_name} integration" do |branches_to_be_notified: nil|
@@ -56,7 +58,7 @@ RSpec.shared_examples "chat integration" do |integration_name|
result = subject.execute(sample_data)
expect(result).to be(true)
- expect(WebMock).to have_requested(:post, webhook_url).once.with { |req|
+ expect(WebMock).to have_requested(:post, webhook_url_regex).once.with { |req|
json_body = Gitlab::Json.parse(req.body).with_indifferent_access
expect(json_body).to include(payload)
}
@@ -72,7 +74,7 @@ RSpec.shared_examples "chat integration" do |integration_name|
result = subject.execute(sample_data)
expect(result).to be_falsy
- expect(WebMock).not_to have_requested(:post, webhook_url)
+ expect(WebMock).not_to have_requested(:post, webhook_url_regex)
end
end
@@ -112,14 +114,14 @@ RSpec.shared_examples "chat integration" do |integration_name|
end
context "with protected branch" do
- before do
- create(:protected_branch, :create_branch_on_repository, project: project, name: "a-protected-branch")
- end
-
let(:sample_data) do
Gitlab::DataBuilder::Push.build(project: project, user: user, ref: "a-protected-branch")
end
+ before_all do
+ create(:protected_branch, :create_branch_on_repository, project: project, name: "a-protected-branch")
+ end
+
context "when only default branch are to be notified" do
it_behaves_like "untriggered #{integration_name} integration", branches_to_be_notified: "default"
end
@@ -214,7 +216,7 @@ RSpec.shared_examples "chat integration" do |integration_name|
let(:sample_data) { Gitlab::DataBuilder::Note.build(note, user) }
context "with commit comment" do
- let(:note) do
+ let_it_be(:note) do
create(:note_on_commit,
author: user,
project: project,
@@ -226,7 +228,7 @@ RSpec.shared_examples "chat integration" do |integration_name|
end
context "with merge request comment" do
- let(:note) do
+ let_it_be(:note) do
create(:note_on_merge_request, project: project, note: "merge request note")
end
@@ -234,7 +236,7 @@ RSpec.shared_examples "chat integration" do |integration_name|
end
context "with issue comment" do
- let(:note) do
+ let_it_be(:note) do
create(:note_on_issue, project: project, note: "issue note")
end
@@ -242,7 +244,7 @@ RSpec.shared_examples "chat integration" do |integration_name|
end
context "with snippet comment" do
- let(:note) do
+ let_it_be(:note) do
create(:note_on_project_snippet, project: project, note: "snippet note")
end
@@ -251,22 +253,24 @@ RSpec.shared_examples "chat integration" do |integration_name|
end
context "with pipeline events" do
- let(:pipeline) do
- create(:ci_pipeline,
- project: project, status: status,
- sha: project.commit.sha, ref: project.default_branch)
- end
-
let(:sample_data) { Gitlab::DataBuilder::Pipeline.build(pipeline) }
context "with failed pipeline" do
- let(:status) { "failed" }
+ let_it_be(:pipeline) do
+ create(:ci_pipeline,
+ project: project, status: "failed",
+ sha: project.commit.sha, ref: project.default_branch)
+ end
it_behaves_like "triggered #{integration_name} integration"
end
context "with succeeded pipeline" do
- let(:status) { "success" }
+ let_it_be(:pipeline) do
+ create(:ci_pipeline,
+ project: project, status: "success",
+ sha: project.commit.sha, ref: project.default_branch)
+ end
context "with default notify_only_broken_pipelines" do
it "does not call #{integration_name} API" do
@@ -308,7 +312,7 @@ RSpec.shared_examples "chat integration" do |integration_name|
end
context "with protected branch" do
- before do
+ before_all do
create(:protected_branch, :create_branch_on_repository, project: project, name: "a-protected-branch")
end
@@ -357,7 +361,8 @@ RSpec.shared_examples "chat integration" do |integration_name|
end
context 'deployment events' do
- let(:deployment) { create(:deployment) }
+ let_it_be(:deployment) { create(:deployment) }
+
let(:sample_data) { Gitlab::DataBuilder::Deployment.build(deployment, deployment.status, Time.now) }
it_behaves_like "untriggered #{integration_name} integration"