]> cat aescling's git repositories - mastodon.git/commitdiff
make it not return http 400 when passing and empty source argument (#12259)
authorJennifer Glauche <=^.^=@github19.jglauche.de>
Sat, 16 Nov 2019 18:02:09 +0000 (19:02 +0100)
committerEugen Rochko <eugen@zeonfederated.com>
Sat, 16 Nov 2019 18:02:09 +0000 (19:02 +0100)
* make it not return http 400 when passing and empty source argument

* create a spec for the empty source hash bug

* compact checks for nil, empty? parameters

* use nil.blank? instead checking for nil

app/controllers/api/v1/accounts/credentials_controller.rb
spec/controllers/api/v1/accounts/credentials_controller_spec.rb

index e77f57910b2bfbcbe11c0fb958bb7b9eb43e3f63..64b5cb747cd6c0b95791e1f18369ab9f24954f6f 100644 (file)
@@ -25,7 +25,7 @@ class Api::V1::Accounts::CredentialsController < Api::BaseController
   end
 
   def user_settings_params
-    return nil unless params.key?(:source)
+    return nil if params[:source].blank?
 
     source_params = params.require(:source)
 
index 19ac32612858962721baa4edd7ee3132f1ff50c7..ebd462a039421c0470b4137593aa6210d4a65980 100644 (file)
@@ -59,6 +59,19 @@ describe Api::V1::Accounts::CredentialsController do
         end
       end
 
+      describe 'with empty source list' do
+        before do
+          patch :update, params: {
+            display_name: "I'm a cat",
+            source: {},
+          }, as: :json
+        end
+
+        it 'returns http success' do
+          expect(response).to have_http_status(200)
+        end
+     end
+
       describe 'with invalid data' do
         before do
           patch :update, params: { note: 'This is too long. ' * 30 }