From 80ab485eb6ec4720f5435d8339156c951aa2bea4 Mon Sep 17 00:00:00 2001 From: rhymes Date: Thu, 7 Nov 2019 20:11:11 +0100 Subject: [PATCH] Fix http status code for rate limiting (#4742) --- app/controllers/follows_controller.rb | 5 +---- spec/requests/follows_create_spec.rb | 5 +++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/app/controllers/follows_controller.rb b/app/controllers/follows_controller.rb index 7bc82fcf0..e8de37aa8 100644 --- a/app/controllers/follows_controller.rb +++ b/app/controllers/follows_controller.rb @@ -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) diff --git a/spec/requests/follows_create_spec.rb b/spec/requests/follows_create_spec.rb index 80d6b5f5b..5d5055dee 100644 --- a/spec/requests/follows_create_spec.rb +++ b/spec/requests/follows_create_spec.rb @@ -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