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
) }
11 context
'activity is reblog' do
12 let(:activity) { reblog
}
14 it
'returns status' do
15 expect(notification
.target_status
).to eq status
19 context
'activity is favourite' do
20 let(:type) { :favourite }
21 let(:activity) { favourite
}
23 it
'returns status' do
24 expect(notification
.target_status
).to eq status
28 context
'activity is mention' do
29 let(:activity) { mention
}
31 it
'returns status' do
32 expect(notification
.target_status
).to eq status
38 it
'returns :reblog for a Status' do
39 notification
= Notification
.new(activity
: Status
.new
)
40 expect(notification
.type
).to eq
:reblog
43 it
'returns :mention for a Mention' do
44 notification
= Notification
.new(activity
: Mention
.new
)
45 expect(notification
.type
).to eq
:mention
48 it
'returns :favourite for a Favourite' do
49 notification
= Notification
.new(activity
: Favourite
.new
)
50 expect(notification
.type
).to eq
:favourite
53 it
'returns :follow for a Follow' do
54 notification
= Notification
.new(activity
: Follow
.new
)
55 expect(notification
.type
).to eq
:follow
59 describe
'.reload_stale_associations!' do
60 context 'account_ids are empty
' do
61 let(:cached_items) { [] }
63 subject { described_class.reload_stale_associations!(cached_items
) }
70 context
'account_ids are present' 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
)
79 Fabricate(:notification, activity
: Fabricate(:status)),
80 Fabricate(:notification, activity
: Fabricate(:follow)),
84 let(:stale_account1) { cached_items
[0].from_account
}
85 let(:stale_account2) { cached_items
[1].from_account
}
87 let(:account1) { Fabricate(:account) }
88 let(:account2) { Fabricate(:account) }
90 let(:accounts_with_ids) { { account1
.id
=> account1
, account2
.id
=> account2
} }
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
96 described_class
.reload_stale_associations!
(cached_items
)
98 expect(cached_items
[0].from_account
).to be account1
99 expect(cached_items
[1].from_account
).to be account2