diff options
Diffstat (limited to 'spec/support/shared_examples/controllers/rate_limited_endpoint_shared_examples.rb')
-rw-r--r-- | spec/support/shared_examples/controllers/rate_limited_endpoint_shared_examples.rb | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/spec/support/shared_examples/controllers/rate_limited_endpoint_shared_examples.rb b/spec/support/shared_examples/controllers/rate_limited_endpoint_shared_examples.rb index bb2a4159071..20edca1ee9f 100644 --- a/spec/support/shared_examples/controllers/rate_limited_endpoint_shared_examples.rb +++ b/spec/support/shared_examples/controllers/rate_limited_endpoint_shared_examples.rb @@ -13,10 +13,16 @@ RSpec.shared_examples 'rate limited endpoint' do |rate_limit_key:| env: :"#{rate_limit_key}_request_limit", remote_ip: kind_of(String), request_method: kind_of(String), - path: kind_of(String), - user_id: current_user.id, - username: current_user.username - } + path: kind_of(String) + }.merge(expected_user_attributes) + end + + let(:expected_user_attributes) do + if defined?(current_user) && current_user.present? + { user_id: current_user.id, username: current_user.username } + else + {} + end end let(:error_message) { _('This endpoint has been requested too many times. Try again later.') } |