about summary refs log tree commit diff
path: root/spec/models
diff options
context:
space:
mode:
authorysksn <bluewhale1982@gmail.com>2019-01-11 16:26:03 +0900
committerEugen Rochko <eugen@zeonfederated.com>2019-01-11 07:26:03 +0000
commit09c3c96607c95bf380ace9c109f2672703c679b9 (patch)
tree2e22f17f09c92eee7421707d0776953e41354e81 /spec/models
parent70801b850c78d7879182eeba4eae509af42fafeb (diff)
Add specs for Admin::AccountAction (#9767)
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/admin/account_action_spec.rb127
1 files changed, 127 insertions, 0 deletions
diff --git a/spec/models/admin/account_action_spec.rb b/spec/models/admin/account_action_spec.rb
index 8c55cf4dd..a3db60cfc 100644
--- a/spec/models/admin/account_action_spec.rb
+++ b/spec/models/admin/account_action_spec.rb
@@ -1,4 +1,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 queue_email!' do
+      expect(account_action).to receive(:queue_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", "silence", "suspend"]' do
+        expect(subject).to eq %w(none disable silence suspend)
+      end
+    end
+
+    context '!account.local?' do
+      let(:account) { Fabricate(:account, domain: 'hoge.com') }
+
+      it 'returns ["silence", "suspend"]' do
+        expect(subject).to eq %w(silence suspend)
+      end
+    end
+  end
 end