diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/models/account_spec.rb | 31 | ||||
-rw-r--r-- | spec/models/status_spec.rb | 14 |
2 files changed, 45 insertions, 0 deletions
diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb index 3aaaa55eb..cce659a8a 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 aee4f49b4..5113b652f 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 |