account_action_spec.rb 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. require 'rails_helper'
  2. RSpec.describe Admin::AccountAction, type: :model do
  3. let(:account_action) { described_class.new }
  4. describe '#save!' do
  5. subject { account_action.save! }
  6. let(:account) { Fabricate(:account, user: Fabricate(:user, admin: true)) }
  7. let(:target_account) { Fabricate(:account, user: Fabricate(:user)) }
  8. let(:type) { 'disable' }
  9. before do
  10. account_action.assign_attributes(
  11. type: type,
  12. current_account: account,
  13. target_account: target_account
  14. )
  15. end
  16. context 'type is "disable"' do
  17. let(:type) { 'disable' }
  18. it 'disable user' do
  19. subject
  20. expect(target_account.user).to be_disabled
  21. end
  22. end
  23. context 'type is "silence"' do
  24. let(:type) { 'silence' }
  25. it 'silences account' do
  26. subject
  27. expect(target_account).to be_silenced
  28. end
  29. end
  30. context 'type is "suspend"' do
  31. let(:type) { 'suspend' }
  32. it 'suspends account' do
  33. subject
  34. expect(target_account).to be_suspended
  35. end
  36. it 'queues Admin::SuspensionWorker by 1' do
  37. Sidekiq::Testing.fake! do
  38. expect do
  39. subject
  40. end.to change { Admin::SuspensionWorker.jobs.size }.by 1
  41. end
  42. end
  43. end
  44. it 'creates Admin::ActionLog' do
  45. expect do
  46. subject
  47. end.to change { Admin::ActionLog.count }.by 1
  48. end
  49. it 'calls process_email!' do
  50. expect(account_action).to receive(:process_email!)
  51. subject
  52. end
  53. it 'calls process_reports!' do
  54. expect(account_action).to receive(:process_reports!)
  55. subject
  56. end
  57. end
  58. describe '#report' do
  59. subject { account_action.report }
  60. context 'report_id.present?' do
  61. before do
  62. account_action.report_id = Fabricate(:report).id
  63. end
  64. it 'returns Report' do
  65. expect(subject).to be_instance_of Report
  66. end
  67. end
  68. context '!report_id.present?' do
  69. it 'returns nil' do
  70. expect(subject).to be_nil
  71. end
  72. end
  73. end
  74. describe '#with_report?' do
  75. subject { account_action.with_report? }
  76. context '!report.nil?' do
  77. before do
  78. account_action.report_id = Fabricate(:report).id
  79. end
  80. it 'returns true' do
  81. expect(subject).to be true
  82. end
  83. end
  84. context '!(!report.nil?)' do
  85. it 'returns false' do
  86. expect(subject).to be false
  87. end
  88. end
  89. end
  90. describe '.types_for_account' do
  91. subject { described_class.types_for_account(account) }
  92. context 'account.local?' do
  93. let(:account) { Fabricate(:account, domain: nil) }
  94. it 'returns ["none", "disable", "silence", "suspend"]' do
  95. expect(subject).to eq %w(none disable silence suspend)
  96. end
  97. end
  98. context '!account.local?' do
  99. let(:account) { Fabricate(:account, domain: 'hoge.com') }
  100. it 'returns ["silence", "suspend"]' do
  101. expect(subject).to eq %w(silence suspend)
  102. end
  103. end
  104. end
  105. end