1
0
mirror of https://github.com/funamitech/mastodon synced 2024-11-28 06:48:45 +09:00
YuruToot/spec/models/notification_spec.rb
ThibG 911cc14481 Add follow_request notification type (#12198)
* Add follow_request notification type

The notification type already existed in the backend but was never pushed
to the front-end. This also means translation strings were also available
for the backend, from the notification mailer.

Unlike other notification types, these are off by default, to match what
I remember of Gargron's view on the topic: that follow requests should not
clutter notifications and should instead be reviewed at the user's own
leisure in the dedicated column.

Since follow requests have their own column, I've deemed it unnecessary to
add a specific tab for them in the notification quick filter.

* Show follow request link in single-column if there are pending requests, even if account isn't locked

* Push follow requests from notifications to the follow_requests list

* Offer to accept or reject follow request from the notification

* Redesign follow request notification
2019-12-01 17:25:29 +01:00

104 lines
3.1 KiB
Ruby

require 'rails_helper'
RSpec.describe Notification, type: :model do
describe '#target_status' do
let(:notification) { Fabricate(:notification, activity: activity) }
let(:status) { Fabricate(:status) }
let(:reblog) { Fabricate(:status, reblog: status) }
let(:favourite) { Fabricate(:favourite, status: status) }
let(:mention) { Fabricate(:mention, status: status) }
context 'activity is reblog' do
let(:activity) { reblog }
it 'returns status' do
expect(notification.target_status).to eq status
end
end
context 'activity is favourite' do
let(:type) { :favourite }
let(:activity) { favourite }
it 'returns status' do
expect(notification.target_status).to eq status
end
end
context 'activity is mention' do
let(:activity) { mention }
it 'returns status' do
expect(notification.target_status).to eq status
end
end
end
describe '#type' do
it 'returns :reblog for a Status' do
notification = Notification.new(activity: Status.new)
expect(notification.type).to eq :reblog
end
it 'returns :mention for a Mention' do
notification = Notification.new(activity: Mention.new)
expect(notification.type).to eq :mention
end
it 'returns :favourite for a Favourite' do
notification = Notification.new(activity: Favourite.new)
expect(notification.type).to eq :favourite
end
it 'returns :follow for a Follow' do
notification = Notification.new(activity: Follow.new)
expect(notification.type).to eq :follow
end
end
describe '.reload_stale_associations!' do
context 'account_ids are empty' do
let(:cached_items) { [] }
subject { described_class.reload_stale_associations!(cached_items) }
it 'returns nil' do
is_expected.to be nil
end
end
context 'account_ids are present' do
before do
allow(accounts_with_ids).to receive(:[]).with(stale_account1.id).and_return(account1)
allow(accounts_with_ids).to receive(:[]).with(stale_account2.id).and_return(account2)
allow(Account).to receive_message_chain(:where, :includes, :each_with_object).and_return(accounts_with_ids)
end
let(:cached_items) do
[
Fabricate(:notification, activity: Fabricate(:status)),
Fabricate(:notification, activity: Fabricate(:follow)),
]
end
let(:stale_account1) { cached_items[0].from_account }
let(:stale_account2) { cached_items[1].from_account }
let(:account1) { Fabricate(:account) }
let(:account2) { Fabricate(:account) }
let(:accounts_with_ids) { { account1.id => account1, account2.id => account2 } }
it 'reloads associations' do
expect(cached_items[0].from_account).to be stale_account1
expect(cached_items[1].from_account).to be stale_account2
described_class.reload_stale_associations!(cached_items)
expect(cached_items[0].from_account).to be account1
expect(cached_items[1].from_account).to be account2
end
end
end
end