]> cat aescling's git repositories - mastodon.git/commitdiff
Fix bug in relationships API introduced by #6482 (#6527)
authorEugen Rochko <eugen@zeonfederated.com>
Wed, 21 Feb 2018 22:22:12 +0000 (23:22 +0100)
committerGitHub <noreply@github.com>
Wed, 21 Feb 2018 22:22:12 +0000 (23:22 +0100)
It was merge when it needed to be deep_merge. And added some tests

app/controllers/api/v1/accounts/relationships_controller.rb
app/presenters/account_relationships_presenter.rb
spec/controllers/api/v1/accounts/relationships_controller_spec.rb

index 6cc3da498519bf3fbf1b183d23967bbc7b7ebc5b..70236d1a8bfc1cf6a9c2c17106b062200e851adc 100644 (file)
@@ -21,6 +21,6 @@ class Api::V1::Accounts::RelationshipsController < Api::BaseController
   end
 
   def account_ids
-    @_account_ids ||= Array(params[:id]).map(&:to_i)
+    Array(params[:id]).map(&:to_i)
   end
 end
index d27fb7b01d8eb2bfdd6465593bdd5913ec9a07fd..b1e99b31b7c3641c23197c2ba8524679e7862ffc 100644 (file)
@@ -45,7 +45,7 @@ class AccountRelationshipsPresenter
       maps_for_account = Rails.cache.read("relationship:#{@current_account_id}:#{account_id}")
 
       if maps_for_account.is_a?(Hash)
-        @cached.merge!(maps_for_account)
+        @cached.deep_merge!(maps_for_account)
       else
         @uncached_account_ids << account_id
       end
index 508415fc8cdb9f9ab2e413b06bdf01e29e87ff5b..e0de790c8365ae68755e84ba86e6fa56a7caf1ce 100644 (file)
@@ -66,6 +66,28 @@ describe Api::V1::Accounts::RelationshipsController do
         expect(json.second[:requested]).to be false
         expect(json.second[:domain_blocking]).to be false
       end
+
+      it 'returns JSON with correct data on cached requests too' do
+        get :index, params: { id: [simon.id] }
+
+        json = body_as_json
+
+        expect(json).to be_a Enumerable
+        expect(json.first[:following]).to be true
+        expect(json.first[:showing_reblogs]).to be true
+      end
+
+      it 'returns JSON with correct data after change too' do
+        user.account.unfollow!(simon)
+
+        get :index, params: { id: [simon.id] }
+
+        json = body_as_json
+
+        expect(json).to be_a Enumerable
+        expect(json.first[:following]).to be false
+        expect(json.first[:showing_reblogs]).to be false
+      end
     end
   end
 end