Fix http status code for rate limiting (#4742)
This commit is contained in:
parent
3fad464765
commit
80ab485eb6
2 changed files with 4 additions and 6 deletions
|
|
@ -39,10 +39,7 @@ class FollowsController < ApplicationController
|
|||
else
|
||||
rate_limiter = RateLimitChecker.new(current_user)
|
||||
if rate_limiter.limit_by_action("follow_account")
|
||||
render json: {
|
||||
error: "Daily account follow limit reached!",
|
||||
status: :too_many_requests
|
||||
}
|
||||
render json: { error: "Daily account follow limit reached!" }, status: :too_many_requests
|
||||
return
|
||||
end
|
||||
follow(followable, need_notification: need_notification)
|
||||
|
|
|
|||
|
|
@ -22,17 +22,18 @@ RSpec.describe "Follows #create", type: :request do
|
|||
|
||||
allow(rate_limit_checker).
|
||||
to receive(:user_today_follow_count).
|
||||
and_return(501)
|
||||
and_return(RateLimitChecker.daily_account_follow_limit + 1)
|
||||
|
||||
allow(RateLimitChecker).
|
||||
to receive(:new).
|
||||
and_return(rate_limit_checker)
|
||||
end
|
||||
|
||||
it "raises an error for too many follows in a day" do
|
||||
it "returns an error for too many follows in a day" do
|
||||
post "/follows", headers: headers, params: follow_payload
|
||||
json_response = JSON.parse(response.body)
|
||||
|
||||
expect(response).to have_http_status(:too_many_requests)
|
||||
expect(json_response["error"]).to eq("Daily account follow limit reached!")
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue