mirror of
https://git.kescher.at/CatCatNya/catstodon.git
synced 2024-11-28 22:11:49 +01:00
Expand coverage for Export
utility class (#32212)
This commit is contained in:
parent
cbf1349370
commit
243a85ec8d
2 changed files with 144 additions and 35 deletions
|
@ -2,5 +2,5 @@
|
||||||
|
|
||||||
Fabricator(:account_domain_block) do
|
Fabricator(:account_domain_block) do
|
||||||
account { Fabricate.build(:account) }
|
account { Fabricate.build(:account) }
|
||||||
domain 'example.com'
|
domain { sequence { |n| "host-#{n}.example" } }
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,66 +3,175 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe Export do
|
RSpec.describe Export do
|
||||||
|
subject { described_class.new(account) }
|
||||||
|
|
||||||
let(:account) { Fabricate(:account) }
|
let(:account) { Fabricate(:account) }
|
||||||
let(:target_accounts) do
|
let(:target_accounts) do
|
||||||
[{}, { username: 'one', domain: 'local.host' }].map(&method(:Fabricate).curry(2).call(:account))
|
[
|
||||||
|
Fabricate(:account),
|
||||||
|
Fabricate(:account, username: 'one', domain: 'local.host'),
|
||||||
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'to_csv' do
|
describe '#to_bookmarks_csv' do
|
||||||
it 'returns a csv of the blocked accounts' do
|
before { Fabricate.times(2, :bookmark, account: account) }
|
||||||
target_accounts.each { |target_account| account.block!(target_account) }
|
|
||||||
|
|
||||||
export = described_class.new(account).to_blocked_accounts_csv
|
let(:export) { CSV.parse(subject.to_bookmarks_csv) }
|
||||||
results = export.strip.split
|
|
||||||
|
|
||||||
expect(results.size).to eq 2
|
it 'returns a csv of bookmarks' do
|
||||||
expect(results.first).to eq 'one@local.host'
|
expect(export)
|
||||||
|
.to contain_exactly(
|
||||||
|
include(/statuses/),
|
||||||
|
include(/statuses/)
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#to_blocked_accounts_csv' do
|
||||||
|
before { target_accounts.each { |target_account| account.block!(target_account) } }
|
||||||
|
|
||||||
|
let(:export) { CSV.parse(subject.to_blocked_accounts_csv) }
|
||||||
|
|
||||||
|
it 'returns a csv of the blocked accounts' do
|
||||||
|
expect(export)
|
||||||
|
.to contain_exactly(
|
||||||
|
include('one@local.host'),
|
||||||
|
include(be_present)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#to_muted_accounts_csv' do
|
||||||
|
before { target_accounts.each { |target_account| account.mute!(target_account) } }
|
||||||
|
|
||||||
|
let(:export) { CSV.parse(subject.to_muted_accounts_csv) }
|
||||||
|
|
||||||
it 'returns a csv of the muted accounts' do
|
it 'returns a csv of the muted accounts' do
|
||||||
target_accounts.each { |target_account| account.mute!(target_account) }
|
expect(export)
|
||||||
|
.to contain_exactly(
|
||||||
export = described_class.new(account).to_muted_accounts_csv
|
contain_exactly('Account address', 'Hide notifications'),
|
||||||
results = export.strip.split("\n")
|
include('one@local.host', 'true'),
|
||||||
|
include(be_present)
|
||||||
expect(results.size).to eq 3
|
)
|
||||||
expect(results.first).to eq 'Account address,Hide notifications'
|
|
||||||
expect(results.second).to eq 'one@local.host,true'
|
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#to_following_accounts_csv' do
|
||||||
|
before { target_accounts.each { |target_account| account.follow!(target_account) } }
|
||||||
|
|
||||||
|
let(:export) { CSV.parse(subject.to_following_accounts_csv) }
|
||||||
|
|
||||||
it 'returns a csv of the following accounts' do
|
it 'returns a csv of the following accounts' do
|
||||||
target_accounts.each { |target_account| account.follow!(target_account) }
|
expect(export)
|
||||||
|
.to contain_exactly(
|
||||||
export = described_class.new(account).to_following_accounts_csv
|
contain_exactly('Account address', 'Show boosts', 'Notify on new posts', 'Languages'),
|
||||||
results = export.strip.split("\n")
|
include('one@local.host', 'true', 'false', be_blank),
|
||||||
|
include(be_present)
|
||||||
expect(results.size).to eq 3
|
)
|
||||||
expect(results.first).to eq 'Account address,Show boosts,Notify on new posts,Languages'
|
|
||||||
expect(results.second).to eq 'one@local.host,true,false,'
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'total_storage' do
|
describe '#to_lists_csv' do
|
||||||
|
before do
|
||||||
|
target_accounts.each do |target_account|
|
||||||
|
account.follow!(target_account)
|
||||||
|
Fabricate(:list, account: account).accounts << target_account
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
let(:export) { CSV.parse(subject.to_lists_csv) }
|
||||||
|
|
||||||
|
it 'returns a csv of the lists' do
|
||||||
|
expect(export)
|
||||||
|
.to contain_exactly(
|
||||||
|
include('one@local.host'),
|
||||||
|
include(be_present)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#to_blocked_domains_csv' do
|
||||||
|
before { Fabricate.times(2, :account_domain_block, account: account) }
|
||||||
|
|
||||||
|
let(:export) { CSV.parse(subject.to_blocked_domains_csv) }
|
||||||
|
|
||||||
|
it 'returns a csv of the blocked domains' do
|
||||||
|
expect(export)
|
||||||
|
.to contain_exactly(
|
||||||
|
include(/example/),
|
||||||
|
include(/example/)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#total_storage' do
|
||||||
it 'returns the total size of the media attachments' do
|
it 'returns the total size of the media attachments' do
|
||||||
media_attachment = Fabricate(:media_attachment, account: account)
|
media_attachment = Fabricate(:media_attachment, account: account)
|
||||||
expect(described_class.new(account).total_storage).to eq media_attachment.file_file_size || 0
|
expect(subject.total_storage).to eq media_attachment.file_file_size || 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'total_follows' do
|
describe '#total_statuses' do
|
||||||
it 'returns the total number of the followed accounts' do
|
before { Fabricate.times(2, :status, account: account) }
|
||||||
target_accounts.each { |target_account| account.follow!(target_account) }
|
|
||||||
expect(described_class.new(account.reload).total_follows).to eq 2
|
it 'returns the total number of statuses' do
|
||||||
|
expect(subject.total_statuses).to eq(2)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#total_bookmarks' do
|
||||||
|
before { Fabricate.times(2, :bookmark, account: account) }
|
||||||
|
|
||||||
|
it 'returns the total number of bookmarks' do
|
||||||
|
expect(subject.total_bookmarks).to eq(2)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#total_follows' do
|
||||||
|
before { target_accounts.each { |target_account| account.follow!(target_account) } }
|
||||||
|
|
||||||
|
it 'returns the total number of the followed accounts' do
|
||||||
|
expect(subject.total_follows).to eq(2)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#total_lists' do
|
||||||
|
before { Fabricate.times(2, :list, account: account) }
|
||||||
|
|
||||||
|
it 'returns the total number of lists' do
|
||||||
|
expect(subject.total_lists).to eq(2)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#total_followers' do
|
||||||
|
before { target_accounts.each { |target_account| target_account.follow!(account) } }
|
||||||
|
|
||||||
|
it 'returns the total number of the follower accounts' do
|
||||||
|
expect(subject.total_followers).to eq(2)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#total_blocks' do
|
||||||
|
before { target_accounts.each { |target_account| account.block!(target_account) } }
|
||||||
|
|
||||||
it 'returns the total number of the blocked accounts' do
|
it 'returns the total number of the blocked accounts' do
|
||||||
target_accounts.each { |target_account| account.block!(target_account) }
|
expect(subject.total_blocks).to eq(2)
|
||||||
expect(described_class.new(account.reload).total_blocks).to eq 2
|
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#total_mutes' do
|
||||||
|
before { target_accounts.each { |target_account| account.mute!(target_account) } }
|
||||||
|
|
||||||
it 'returns the total number of the muted accounts' do
|
it 'returns the total number of the muted accounts' do
|
||||||
target_accounts.each { |target_account| account.mute!(target_account) }
|
expect(subject.total_mutes).to eq(2)
|
||||||
expect(described_class.new(account.reload).total_mutes).to eq 2
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#total_domain_blocks' do
|
||||||
|
before { Fabricate.times(2, :account_domain_block, account: account) }
|
||||||
|
|
||||||
|
it 'returns the total number of account domain blocks' do
|
||||||
|
expect(subject.total_domain_blocks).to eq(2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue