export_spec.rb 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe Export do
  4. subject { described_class.new(account) }
  5. let(:account) { Fabricate(:account) }
  6. let(:target_accounts) do
  7. [
  8. Fabricate(:account),
  9. Fabricate(:account, username: 'one', domain: 'local.host'),
  10. ]
  11. end
  12. describe '#to_bookmarks_csv' do
  13. before { Fabricate.times(2, :bookmark, account: account) }
  14. let(:export) { CSV.parse(subject.to_bookmarks_csv) }
  15. it 'returns a csv of bookmarks' do
  16. expect(export)
  17. .to contain_exactly(
  18. include(/statuses/),
  19. include(/statuses/)
  20. )
  21. end
  22. end
  23. describe '#to_blocked_accounts_csv' do
  24. before { target_accounts.each { |target_account| account.block!(target_account) } }
  25. let(:export) { CSV.parse(subject.to_blocked_accounts_csv) }
  26. it 'returns a csv of the blocked accounts' do
  27. expect(export)
  28. .to contain_exactly(
  29. include('one@local.host'),
  30. include(be_present)
  31. )
  32. end
  33. end
  34. describe '#to_muted_accounts_csv' do
  35. before { target_accounts.each { |target_account| account.mute!(target_account) } }
  36. let(:export) { CSV.parse(subject.to_muted_accounts_csv) }
  37. it 'returns a csv of the muted accounts' do
  38. expect(export)
  39. .to contain_exactly(
  40. contain_exactly('Account address', 'Hide notifications'),
  41. include('one@local.host', 'true'),
  42. include(be_present)
  43. )
  44. end
  45. end
  46. describe '#to_following_accounts_csv' do
  47. before { target_accounts.each { |target_account| account.follow!(target_account) } }
  48. let(:export) { CSV.parse(subject.to_following_accounts_csv) }
  49. it 'returns a csv of the following accounts' do
  50. expect(export)
  51. .to contain_exactly(
  52. contain_exactly('Account address', 'Show boosts', 'Notify on new posts', 'Languages'),
  53. include('one@local.host', 'true', 'false', be_blank),
  54. include(be_present)
  55. )
  56. end
  57. end
  58. describe '#to_lists_csv' do
  59. before do
  60. target_accounts.each do |target_account|
  61. account.follow!(target_account)
  62. Fabricate(:list, account: account).accounts << target_account
  63. end
  64. end
  65. let(:export) { CSV.parse(subject.to_lists_csv) }
  66. it 'returns a csv of the lists' do
  67. expect(export)
  68. .to contain_exactly(
  69. include('one@local.host'),
  70. include(be_present)
  71. )
  72. end
  73. end
  74. describe '#to_blocked_domains_csv' do
  75. before { Fabricate.times(2, :account_domain_block, account: account) }
  76. let(:export) { CSV.parse(subject.to_blocked_domains_csv) }
  77. it 'returns a csv of the blocked domains' do
  78. expect(export)
  79. .to contain_exactly(
  80. include(/example/),
  81. include(/example/)
  82. )
  83. end
  84. end
  85. end