Add notification policies and notification requests (#29366)
This commit is contained in:
parent
653ce43abe
commit
50b17f7e10
104 changed files with 1096 additions and 247 deletions
25
spec/models/notification_policy_spec.rb
Normal file
25
spec/models/notification_policy_spec.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe NotificationPolicy do
|
||||
describe '#summarize!' do
|
||||
subject { Fabricate(:notification_policy) }
|
||||
|
||||
let(:sender) { Fabricate(:account) }
|
||||
|
||||
before do
|
||||
Fabricate.times(2, :notification, account: subject.account, activity: Fabricate(:status, account: sender))
|
||||
Fabricate(:notification_request, account: subject.account, from_account: sender)
|
||||
subject.summarize!
|
||||
end
|
||||
|
||||
it 'sets pending_requests_count' do
|
||||
expect(subject.pending_requests_count).to eq 1
|
||||
end
|
||||
|
||||
it 'sets pending_notifications_count' do
|
||||
expect(subject.pending_notifications_count).to eq 2
|
||||
end
|
||||
end
|
||||
end
|
44
spec/models/notification_request_spec.rb
Normal file
44
spec/models/notification_request_spec.rb
Normal file
|
@ -0,0 +1,44 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe NotificationRequest do
|
||||
describe '#reconsider_existence!' do
|
||||
subject { Fabricate(:notification_request, dismissed: dismissed) }
|
||||
|
||||
let(:dismissed) { false }
|
||||
|
||||
context 'when there are remaining notifications' do
|
||||
before do
|
||||
Fabricate(:notification, account: subject.account, activity: Fabricate(:status, account: subject.from_account))
|
||||
subject.reconsider_existence!
|
||||
end
|
||||
|
||||
it 'leaves request intact' do
|
||||
expect(subject.destroyed?).to be false
|
||||
end
|
||||
|
||||
it 'updates notifications_count' do
|
||||
expect(subject.notifications_count).to eq 1
|
||||
end
|
||||
end
|
||||
|
||||
context 'when there are no notifications' do
|
||||
before do
|
||||
subject.reconsider_existence!
|
||||
end
|
||||
|
||||
context 'when dismissed' do
|
||||
let(:dismissed) { true }
|
||||
|
||||
it 'leaves request intact' do
|
||||
expect(subject.destroyed?).to be false
|
||||
end
|
||||
end
|
||||
|
||||
it 'removes the request' do
|
||||
expect(subject.destroyed?).to be true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue