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/services/issues')
-rw-r--r--spec/services/issues/create_service_spec.rb85
-rw-r--r--spec/services/issues/set_crm_contacts_service_spec.rb2
-rw-r--r--spec/services/issues/update_service_spec.rb38
3 files changed, 46 insertions, 79 deletions
diff --git a/spec/services/issues/create_service_spec.rb b/spec/services/issues/create_service_spec.rb
index f4bb1f0877b..6b7b72d83fc 100644
--- a/spec/services/issues/create_service_spec.rb
+++ b/spec/services/issues/create_service_spec.rb
@@ -11,22 +11,12 @@ RSpec.describe Issues::CreateService do
let(:spam_params) { double }
- describe '.rate_limiter_scoped_and_keyed' do
- it 'is set via the rate_limit call' do
- expect(described_class.rate_limiter_scoped_and_keyed).to be_a(RateLimitedService::RateLimiterScopedAndKeyed)
-
- expect(described_class.rate_limiter_scoped_and_keyed.key).to eq(:issues_create)
- expect(described_class.rate_limiter_scoped_and_keyed.opts[:scope]).to eq(%i[project current_user external_author])
- expect(described_class.rate_limiter_scoped_and_keyed.rate_limiter).to eq(Gitlab::ApplicationRateLimiter)
- end
- end
-
- describe '#rate_limiter_bypassed' do
- let(:subject) { described_class.new(project: project, spam_params: {}) }
-
- it 'is nil by default' do
- expect(subject.rate_limiter_bypassed).to be_nil
- end
+ it_behaves_like 'rate limited service' do
+ let(:key) { :issues_create }
+ let(:key_scope) { %i[project current_user external_author] }
+ let(:application_limit_key) { :issues_create_limit }
+ let(:created_model) { Issue }
+ let(:service) { described_class.new(project: project, current_user: user, params: { title: 'title' }, spam_params: double) }
end
describe '#execute' do
@@ -331,44 +321,6 @@ RSpec.describe Issues::CreateService do
described_class.new(project: project, current_user: user, params: opts, spam_params: spam_params).execute
end
- context 'when rate limiting is in effect', :freeze_time, :clean_gitlab_redis_rate_limiting do
- let(:user) { create(:user) }
-
- before do
- stub_feature_flags(rate_limited_service_issues_create: true)
- stub_application_setting(issues_create_limit: 1)
- end
-
- subject do
- 2.times { described_class.new(project: project, current_user: user, params: opts, spam_params: double).execute }
- end
-
- context 'when too many requests are sent by one user' do
- it 'raises an error' do
- expect do
- subject
- end.to raise_error(RateLimitedService::RateLimitedError)
- end
-
- it 'creates 1 issue' do
- expect do
- subject
- rescue RateLimitedService::RateLimitedError
- end.to change { Issue.count }.by(1)
- end
- end
-
- context 'when limit is higher than count of issues being created' do
- before do
- stub_application_setting(issues_create_limit: 2)
- end
-
- it 'creates 2 issues' do
- expect { subject }.to change { Issue.count }.by(2)
- end
- end
- end
-
context 'after_save callback to store_mentions' do
context 'when mentionable attributes change' do
let(:opts) { { title: 'Title', description: "Description with #{user.to_reference}" } }
@@ -574,6 +526,31 @@ RSpec.describe Issues::CreateService do
end
end
+ context 'add related issue' do
+ let_it_be(:related_issue) { create(:issue, project: project) }
+
+ let(:opts) do
+ { title: 'A new issue', add_related_issue: related_issue }
+ end
+
+ it 'ignores related issue if not accessible' do
+ expect { issue }.not_to change { IssueLink.count }
+ expect(issue).to be_persisted
+ end
+
+ context 'when user has access to the related issue' do
+ before do
+ project.add_developer(user)
+ end
+
+ it 'adds a link to the issue' do
+ expect { issue }.to change { IssueLink.count }.by(1)
+ expect(issue).to be_persisted
+ expect(issue.related_issues(user)).to eq([related_issue])
+ end
+ end
+ end
+
context 'checking spam' do
let(:params) do
{
diff --git a/spec/services/issues/set_crm_contacts_service_spec.rb b/spec/services/issues/set_crm_contacts_service_spec.rb
index 64011a7a003..b0befb9f77c 100644
--- a/spec/services/issues/set_crm_contacts_service_spec.rb
+++ b/spec/services/issues/set_crm_contacts_service_spec.rb
@@ -5,7 +5,7 @@ require 'spec_helper'
RSpec.describe Issues::SetCrmContactsService do
let_it_be(:user) { create(:user) }
let_it_be(:group) { create(:group, :crm_enabled) }
- let_it_be(:project) { create(:project, group: group) }
+ let_it_be(:project) { create(:project, group: create(:group, parent: group)) }
let_it_be(:contacts) { create_list(:contact, 4, group: group) }
let_it_be(:issue, reload: true) { create(:issue, project: project) }
let_it_be(:issue_contact_1) do
diff --git a/spec/services/issues/update_service_spec.rb b/spec/services/issues/update_service_spec.rb
index 95394ba6597..6d3c3dd4e39 100644
--- a/spec/services/issues/update_service_spec.rb
+++ b/spec/services/issues/update_service_spec.rb
@@ -1157,6 +1157,13 @@ RSpec.describe Issues::UpdateService, :mailer do
expect(issue.escalation_status.status_name).to eq(expected_status)
end
+
+ it 'triggers webhooks' do
+ expect(project).to receive(:execute_hooks).with(an_instance_of(Hash), :issue_hooks)
+ expect(project).to receive(:execute_integrations).with(an_instance_of(Hash), :issue_hooks)
+
+ update_issue(opts)
+ end
end
shared_examples 'does not change the status record' do
@@ -1169,7 +1176,8 @@ RSpec.describe Issues::UpdateService, :mailer do
end
it 'does not trigger side-effects' do
- expect(escalation_update_class).not_to receive(:new)
+ expect(project).not_to receive(:execute_hooks)
+ expect(project).not_to receive(:execute_integrations)
update_issue(opts)
end
@@ -1324,32 +1332,14 @@ RSpec.describe Issues::UpdateService, :mailer do
context 'broadcasting issue assignee updates' do
let(:update_params) { { assignee_ids: [user2.id] } }
- context 'when feature flag is enabled' do
- before do
- stub_feature_flags(broadcast_issue_updates: true)
- end
+ it 'triggers the GraphQL subscription' do
+ expect(GraphqlTriggers).to receive(:issuable_assignees_updated).with(issue)
- it 'triggers the GraphQL subscription' do
- expect(GraphqlTriggers).to receive(:issuable_assignees_updated).with(issue)
-
- update_issue(update_params)
- end
-
- context 'when assignee is not updated' do
- let(:update_params) { { title: 'Some other title' } }
-
- it 'does not trigger the GraphQL subscription' do
- expect(GraphqlTriggers).not_to receive(:issuable_assignees_updated).with(issue)
-
- update_issue(update_params)
- end
- end
+ update_issue(update_params)
end
- context 'when feature flag is disabled' do
- before do
- stub_feature_flags(broadcast_issue_updates: false)
- end
+ context 'when assignee is not updated' do
+ let(:update_params) { { title: 'Some other title' } }
it 'does not trigger the GraphQL subscription' do
expect(GraphqlTriggers).not_to receive(:issuable_assignees_updated).with(issue)