diff --git a/app/controllers/severed_relationships_controller.rb b/app/controllers/severed_relationships_controller.rb index 9371ebf7d0..a537368530 100644 --- a/app/controllers/severed_relationships_controller.rb +++ b/app/controllers/severed_relationships_controller.rb @@ -13,13 +13,13 @@ class SeveredRelationshipsController < ApplicationController def following respond_to do |format| - format.csv { send_data following_data, filename: "following-#{@event.target_name}-#{@event.created_at.to_date.iso8601}.csv" } + format.csv { send_data following_data, filename: } end end def followers respond_to do |format| - format.csv { send_data followers_data, filename: "followers-#{@event.target_name}-#{@event.created_at.to_date.iso8601}.csv" } + format.csv { send_data followers_data, filename: } end end @@ -48,4 +48,8 @@ class SeveredRelationshipsController < ApplicationController def acct(account) account.local? ? account.local_username_and_domain : account.acct end + + def filename + "#{action_name}-#{@event.identifier}.csv" + end end diff --git a/app/models/account_relationship_severance_event.rb b/app/models/account_relationship_severance_event.rb index 115c63c062..89e6d8b981 100644 --- a/app/models/account_relationship_severance_event.rb +++ b/app/models/account_relationship_severance_event.rb @@ -32,6 +32,10 @@ class AccountRelationshipSeveranceEvent < ApplicationRecord before_create :set_relationships_count! + def identifier + "#{target_name}-#{created_at.to_date.iso8601}" + end + private def set_relationships_count! diff --git a/spec/models/account_relationship_severance_event_spec.rb b/spec/models/account_relationship_severance_event_spec.rb new file mode 100644 index 0000000000..d3a600eee4 --- /dev/null +++ b/spec/models/account_relationship_severance_event_spec.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +RSpec.describe AccountRelationshipSeveranceEvent do + describe 'Associations' do + it { is_expected.to belong_to(:account) } + it { is_expected.to belong_to(:relationship_severance_event) } + it { is_expected.to have_many(:severed_relationships).through(:relationship_severance_event) } + end + + describe '#identifier' do + subject { account_relationship_severance_event.identifier } + + let(:account_relationship_severance_event) { Fabricate.build :account_relationship_severance_event, relationship_severance_event:, created_at: DateTime.new(2026, 3, 15, 1, 2, 3) } + let(:relationship_severance_event) { Fabricate.build :relationship_severance_event, target_name: 'host.example' } + + context 'with a hostname target and timestamp' do + it { is_expected.to eq('host.example-2026-03-15') } + end + end +end