about summary refs log tree commit diff
path: root/spec/models
diff options
context:
space:
mode:
authorJenkins <jenkins@jenkins.ninjawedding.org>2018-05-31 01:17:25 +0000
committerJenkins <jenkins@jenkins.ninjawedding.org>2018-05-31 01:17:25 +0000
commit165b5dc7f5711efd07adb73316e94d89b9e7e3a3 (patch)
treeeafd267dd5b167961455e24bbdba89b025563177 /spec/models
parente7b3a4263e5a22a64b7fdc3a965fa38e1935157a (diff)
parentc61c4565ab17f7e882b93f96e4d97ff1681a7bcf (diff)
Merge remote-tracking branch 'tootsuite/master' into glitchsoc/master
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/account_spec.rb31
-rw-r--r--spec/models/status_spec.rb14
2 files changed, 45 insertions, 0 deletions
diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb
index a88b11482..512b6e661 100644
--- a/spec/models/account_spec.rb
+++ b/spec/models/account_spec.rb
@@ -525,6 +525,37 @@ RSpec.describe Account, type: :model do
     end
   end
 
+  describe '#statuses_count' do
+    subject { Fabricate(:account) }
+
+    it 'counts statuses' do
+      Fabricate(:status, account: subject)
+      Fabricate(:status, account: subject)
+      expect(subject.statuses_count).to eq 2
+    end
+
+    it 'does not count direct statuses' do
+      Fabricate(:status, account: subject, visibility: :direct)
+      expect(subject.statuses_count).to eq 0
+    end
+
+    it 'is decremented when status is removed' do
+      status = Fabricate(:status, account: subject)
+      expect(subject.statuses_count).to eq 1
+      status.destroy
+      expect(subject.statuses_count).to eq 0
+    end
+
+    it 'is decremented when status is removed when account is not preloaded' do
+      status = Fabricate(:status, account: subject)
+      expect(subject.reload.statuses_count).to eq 1
+      clean_status = Status.find(status.id)
+      expect(clean_status.association(:account).loaded?).to be false
+      clean_status.destroy
+      expect(subject.reload.statuses_count).to eq 0
+    end
+  end
+
   describe '.following_map' do
     it 'returns an hash' do
       expect(Account.following_map([], 1)).to be_a Hash
diff --git a/spec/models/status_spec.rb b/spec/models/status_spec.rb
index 03d1a94de..14233e824 100644
--- a/spec/models/status_spec.rb
+++ b/spec/models/status_spec.rb
@@ -175,6 +175,13 @@ RSpec.describe Status, type: :model do
 
       expect(subject.reblogs_count).to eq 2
     end
+
+    it 'is decremented when reblog is removed' do
+      reblog = Fabricate(:status, account: bob, reblog: subject)
+      expect(subject.reblogs_count).to eq 1
+      reblog.destroy
+      expect(subject.reblogs_count).to eq 0
+    end
   end
 
   describe '#favourites_count' do
@@ -184,6 +191,13 @@ RSpec.describe Status, type: :model do
 
       expect(subject.favourites_count).to eq 2
     end
+
+    it 'is decremented when favourite is removed' do
+      favourite = Fabricate(:favourite, account: bob, status: subject)
+      expect(subject.favourites_count).to eq 1
+      favourite.destroy
+      expect(subject.favourites_count).to eq 0
+    end
   end
 
   describe '#proper' do