diff --git a/spec/models/notification_spec.rb b/spec/models/notification_spec.rb index d6e2282022..172d1c65b9 100644 --- a/spec/models/notification_spec.rb +++ b/spec/models/notification_spec.rb @@ -58,6 +58,88 @@ RSpec.describe Notification do end end + describe 'Setting account from activity_type' do + context 'when activity_type is a Status' do + it 'sets the notification from_account correctly' do + status = Fabricate(:status) + + notification = Fabricate.build(:notification, activity_type: 'Status', activity: status) + + expect(notification.from_account).to eq(status.account) + end + end + + context 'when activity_type is a Follow' do + it 'sets the notification from_account correctly' do + follow = Fabricate(:follow) + + notification = Fabricate.build(:notification, activity_type: 'Follow', activity: follow) + + expect(notification.from_account).to eq(follow.account) + end + end + + context 'when activity_type is a Favourite' do + it 'sets the notification from_account correctly' do + favourite = Fabricate(:favourite) + + notification = Fabricate.build(:notification, activity_type: 'Favourite', activity: favourite) + + expect(notification.from_account).to eq(favourite.account) + end + end + + context 'when activity_type is a FollowRequest' do + it 'sets the notification from_account correctly' do + follow_request = Fabricate(:follow_request) + + notification = Fabricate.build(:notification, activity_type: 'FollowRequest', activity: follow_request) + + expect(notification.from_account).to eq(follow_request.account) + end + end + + context 'when activity_type is a Poll' do + it 'sets the notification from_account correctly' do + poll = Fabricate(:poll) + + notification = Fabricate.build(:notification, activity_type: 'Poll', activity: poll) + + expect(notification.from_account).to eq(poll.account) + end + end + + context 'when activity_type is a Report' do + it 'sets the notification from_account correctly' do + report = Fabricate(:report) + + notification = Fabricate.build(:notification, activity_type: 'Report', activity: report) + + expect(notification.from_account).to eq(report.account) + end + end + + context 'when activity_type is a Mention' do + it 'sets the notification from_account correctly' do + mention = Fabricate(:mention) + + notification = Fabricate.build(:notification, activity_type: 'Mention', activity: mention) + + expect(notification.from_account).to eq(mention.status.account) + end + end + + context 'when activity_type is an Account' do + it 'sets the notification from_account correctly' do + account = Fabricate(:account) + + notification = Fabricate.build(:notification, activity_type: 'Account', account: account) + + expect(notification.account).to eq(account) + end + end + end + describe '.preload_cache_collection_target_statuses' do subject do described_class.preload_cache_collection_target_statuses(notifications) do |target_statuses| diff --git a/spec/services/fan_out_on_write_service_spec.rb b/spec/services/fan_out_on_write_service_spec.rb index f657f298de..6ad041193b 100644 --- a/spec/services/fan_out_on_write_service_spec.rb +++ b/spec/services/fan_out_on_write_service_spec.rb @@ -20,6 +20,8 @@ RSpec.describe FanOutOnWriteService, type: :service do ProcessMentionsService.new.call(status) ProcessHashtagsService.new.call(status) + Fabricate(:media_attachment, status: status, account: alice) + allow(redis).to receive(:publish) subject.call(status) @@ -49,6 +51,7 @@ RSpec.describe FanOutOnWriteService, type: :service do it 'is broadcast to the public stream' do expect(redis).to have_received(:publish).with('timeline:public', anything) expect(redis).to have_received(:publish).with('timeline:public:local', anything) + expect(redis).to have_received(:publish).with('timeline:public:media', anything) end end diff --git a/spec/services/remove_status_service_spec.rb b/spec/services/remove_status_service_spec.rb index 08ce0b0456..cd3224e028 100644 --- a/spec/services/remove_status_service_spec.rb +++ b/spec/services/remove_status_service_spec.rb @@ -20,7 +20,8 @@ RSpec.describe RemoveStatusService, type: :service do end context 'when removed status is not a reblog' do - let!(:status) { PostStatusService.new.call(alice, text: "Hello @#{bob.pretty_acct} ThisIsASecret") } + let!(:media_attachment) { Fabricate(:media_attachment, account: alice) } + let!(:status) { PostStatusService.new.call(alice, text: "Hello @#{bob.pretty_acct} ThisIsASecret", media_ids: [media_attachment.id]) } before do FavouriteService.new.call(jeff, status) @@ -37,6 +38,14 @@ RSpec.describe RemoveStatusService, type: :service do expect(HomeFeed.new(jeff).get(10).pluck(:id)).to_not include(status.id) end + it 'publishes to public media timeline' do + allow(redis).to receive(:publish).with(any_args) + + subject.call(status) + + expect(redis).to have_received(:publish).with('timeline:public:media', Oj.dump(event: :delete, payload: status.id.to_s)) + end + it 'sends Delete activity to followers' do subject.call(status) expect(a_request(:post, hank.inbox_url).with(