]> cat aescling's git repositories - mastodon.git/blob - spec/models/notification_spec.rb
Revert "improve status title (#8596)" (#13591)
[mastodon.git] / spec / models / notification_spec.rb
1 require 'rails_helper'
2
3 RSpec.describe Notification, type: :model do
4 describe '#target_status' do
5 let(:notification) { Fabricate(:notification, activity: activity) }
6 let(:status) { Fabricate(:status) }
7 let(:reblog) { Fabricate(:status, reblog: status) }
8 let(:favourite) { Fabricate(:favourite, status: status) }
9 let(:mention) { Fabricate(:mention, status: status) }
10
11 context 'activity is reblog' do
12 let(:activity) { reblog }
13
14 it 'returns status' do
15 expect(notification.target_status).to eq status
16 end
17 end
18
19 context 'activity is favourite' do
20 let(:type) { :favourite }
21 let(:activity) { favourite }
22
23 it 'returns status' do
24 expect(notification.target_status).to eq status
25 end
26 end
27
28 context 'activity is mention' do
29 let(:activity) { mention }
30
31 it 'returns status' do
32 expect(notification.target_status).to eq status
33 end
34 end
35 end
36
37 describe '#type' do
38 it 'returns :reblog for a Status' do
39 notification = Notification.new(activity: Status.new)
40 expect(notification.type).to eq :reblog
41 end
42
43 it 'returns :mention for a Mention' do
44 notification = Notification.new(activity: Mention.new)
45 expect(notification.type).to eq :mention
46 end
47
48 it 'returns :favourite for a Favourite' do
49 notification = Notification.new(activity: Favourite.new)
50 expect(notification.type).to eq :favourite
51 end
52
53 it 'returns :follow for a Follow' do
54 notification = Notification.new(activity: Follow.new)
55 expect(notification.type).to eq :follow
56 end
57 end
58
59 describe '.reload_stale_associations!' do
60 context 'account_ids are empty' do
61 let(:cached_items) { [] }
62
63 subject { described_class.reload_stale_associations!(cached_items) }
64
65 it 'returns nil' do
66 is_expected.to be nil
67 end
68 end
69
70 context 'account_ids are present' do
71 before do
72 allow(accounts_with_ids).to receive(:[]).with(stale_account1.id).and_return(account1)
73 allow(accounts_with_ids).to receive(:[]).with(stale_account2.id).and_return(account2)
74 allow(Account).to receive_message_chain(:where, :includes, :each_with_object).and_return(accounts_with_ids)
75 end
76
77 let(:cached_items) do
78 [
79 Fabricate(:notification, activity: Fabricate(:status)),
80 Fabricate(:notification, activity: Fabricate(:follow)),
81 ]
82 end
83
84 let(:stale_account1) { cached_items[0].from_account }
85 let(:stale_account2) { cached_items[1].from_account }
86
87 let(:account1) { Fabricate(:account) }
88 let(:account2) { Fabricate(:account) }
89
90 let(:accounts_with_ids) { { account1.id => account1, account2.id => account2 } }
91
92 it 'reloads associations' do
93 expect(cached_items[0].from_account).to be stale_account1
94 expect(cached_items[1].from_account).to be stale_account2
95
96 described_class.reload_stale_associations!(cached_items)
97
98 expect(cached_items[0].from_account).to be account1
99 expect(cached_items[1].from_account).to be account2
100 end
101 end
102 end
103 end
This page took 0.097558 seconds and 4 git commands to generate.