]> cat aescling's git repositories - mastodon.git/commitdiff
Retoot count increases without reason (#5363)
authorLex Alexander <l.alexander10@gmail.com>
Fri, 13 Oct 2017 00:52:09 +0000 (14:52 -1000)
committerEugen Rochko <eugen@zeonfederated.com>
Fri, 13 Oct 2017 00:52:09 +0000 (02:52 +0200)
* Retoot count increases without reason

-The store_uri method for Statuses was being called on after_create and causing reblogs to be incremented twice.
-This calls it when the transaction is finished by using after_create_commit.
-Fixes #4916.

* Added test case for after_create_commit callback for checking reblog count.

* Rewrote test to keep original, but added one for only the after_create_commit callback.

app/models/status.rb
spec/services/reblog_service_spec.rb

index 0d249244f3e746b18cda18626ecb952e8ec1b9ee..6db1f2a4c8b1c99b5fa04d0f937fd76f5dd106b5 100644 (file)
@@ -134,7 +134,7 @@ class Status < ApplicationRecord
     CustomEmoji.from_text([spoiler_text, text].join(' '), account.domain)
   end
 
-  after_create :store_uri, if: :local?
+  after_create_commit :store_uri, if: :local?
 
   around_create Mastodon::Snowflake::Callbacks
 
index 0ad5c5f6ba514868a8a25691806b85de7def5962..19d3bb6cb711918d6e6770c773afd0cb94082f9d 100644 (file)
@@ -39,6 +39,12 @@ RSpec.describe ReblogService do
       expect(status.reblogs.count).to eq 1
     end
 
+    describe 'after_create_commit :store_uri' do
+      it 'keeps consistent reblog count' do
+        expect(status.reblogs.count).to eq 1
+      end
+    end
+
     it 'distributes to followers' do
       expect(ActivityPub::DistributionWorker).to have_received(:perform_async)
     end