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