summaryrefslogtreecommitdiff
path: root/spec/services/issues
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-02-23 15:14:44 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-02-23 15:14:44 +0000
commit12f988e7dcb038e82144fcd159b94839044c54cb (patch)
tree7790b8ba06d120205a40004dfb560d9ccba0ea93 /spec/services/issues
parentb286069fdfe9a02beb2a26ce73511159a372002d (diff)
downloadgitlab-ce-12f988e7dcb038e82144fcd159b94839044c54cb.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services/issues')
-rw-r--r--spec/services/issues/create_service_spec.rb59
1 files changed, 6 insertions, 53 deletions
diff --git a/spec/services/issues/create_service_spec.rb b/spec/services/issues/create_service_spec.rb
index 889d368c8d3..14ec3939e83 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,43 +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_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}" } }