mirror of
https://github.com/glitch-soc/mastodon.git
synced 2026-03-29 03:00:33 +02:00
Add private method for event export filename (#38454)
This commit is contained in:
@@ -13,13 +13,13 @@ class SeveredRelationshipsController < ApplicationController
|
|||||||
|
|
||||||
def following
|
def following
|
||||||
respond_to do |format|
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
def followers
|
def followers
|
||||||
respond_to do |format|
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -48,4 +48,8 @@ class SeveredRelationshipsController < ApplicationController
|
|||||||
def acct(account)
|
def acct(account)
|
||||||
account.local? ? account.local_username_and_domain : account.acct
|
account.local? ? account.local_username_and_domain : account.acct
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def filename
|
||||||
|
"#{action_name}-#{@event.identifier}.csv"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -32,6 +32,10 @@ class AccountRelationshipSeveranceEvent < ApplicationRecord
|
|||||||
|
|
||||||
before_create :set_relationships_count!
|
before_create :set_relationships_count!
|
||||||
|
|
||||||
|
def identifier
|
||||||
|
"#{target_name}-#{created_at.to_date.iso8601}"
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def set_relationships_count!
|
def set_relationships_count!
|
||||||
|
|||||||
20
spec/models/account_relationship_severance_event_spec.rb
Normal file
20
spec/models/account_relationship_severance_event_spec.rb
Normal file
@@ -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
|
||||||
Reference in New Issue
Block a user