about summary refs log tree commit diff
path: root/spec
diff options
context:
space:
mode:
authorShuhei Kitagawa <shuheiktgw@users.noreply.github.com>2018-05-03 17:42:36 +0900
committerEugen Rochko <eugen@zeonfederated.com>2018-05-03 10:42:36 +0200
commit28b366d065931507114faf2561990d67eab4981f (patch)
tree1dba727b475a2ec8f8e158b8407c7b120178c273 /spec
parentad5d3134e406c2bcfceca6a1b7dd3dceb6ec1061 (diff)
Add missing tests for report.rb (#7324)
Diffstat (limited to 'spec')
-rw-r--r--spec/models/report_spec.rb95
1 files changed, 95 insertions, 0 deletions
diff --git a/spec/models/report_spec.rb b/spec/models/report_spec.rb
index d40ebf6dc..a0cd0800d 100644
--- a/spec/models/report_spec.rb
+++ b/spec/models/report_spec.rb
@@ -22,6 +22,101 @@ describe Report do
     end
   end
 
+  describe 'assign_to_self!' do
+    subject { report.assigned_account_id }
+
+    let(:report) { Fabricate(:report, assigned_account_id: original_account) }
+    let(:original_account) { Fabricate(:account) }
+    let(:current_account) { Fabricate(:account) }
+
+    before do
+      report.assign_to_self!(current_account)
+    end
+
+    it 'assigns to a given account' do
+      is_expected.to eq current_account.id
+    end
+  end
+
+  describe 'unassign!' do
+    subject { report.assigned_account_id }
+
+    let(:report) { Fabricate(:report, assigned_account_id: account.id) }
+    let(:account) { Fabricate(:account) }
+
+    before do
+      report.unassign!
+    end
+
+    it 'unassigns' do
+      is_expected.to be_nil
+    end
+  end
+
+  describe 'resolve!' do
+    subject(:report) { Fabricate(:report, action_taken: false, action_taken_by_account_id: nil) }
+
+    let(:acting_account) { Fabricate(:account) }
+
+    before do
+      report.resolve!(acting_account)
+    end
+
+    it 'records action taken' do
+      expect(report).to have_attributes(action_taken: true, action_taken_by_account_id: acting_account.id)
+    end
+  end
+
+  describe 'unresolve!' do
+    subject(:report) { Fabricate(:report, action_taken: true, action_taken_by_account_id: acting_account.id) }
+
+    let(:acting_account) { Fabricate(:account) }
+
+    before do
+      report.unresolve!
+    end
+
+    it 'unresolves' do
+      expect(report).to have_attributes(action_taken: false, action_taken_by_account_id: nil)
+    end
+  end
+
+  describe 'unresolved?' do
+    subject { report.unresolved? }
+
+    let(:report) { Fabricate(:report, action_taken: action_taken) }
+
+    context 'if action is taken' do
+      let(:action_taken) { true }
+
+      it { is_expected.to be false }
+    end
+
+    context 'if action not is taken' do
+      let(:action_taken) { false }
+
+      it { is_expected.to be true }
+    end
+  end
+
+  describe 'history' do
+    subject(:action_logs) { report.history }
+
+    let(:report) { Fabricate(:report, target_account_id: target_account.id, status_ids: [status.id], created_at: 3.days.ago, updated_at: 1.day.ago) }
+    let(:target_account) { Fabricate(:account) }
+    let(:status) { Fabricate(:status) }
+
+    before do
+      Fabricate('Admin::ActionLog', target_type: 'Report', account_id: target_account.id, target_id: report.id, created_at: 2.days.ago)
+      Fabricate('Admin::ActionLog', target_type: 'Account', account_id: target_account.id, target_id: report.target_account_id, created_at: 2.days.ago)
+      Fabricate('Admin::ActionLog', target_type: 'Status', account_id: target_account.id, target_id: status.id, created_at: 2.days.ago)
+    end
+
+    it 'returns right logs' do
+      expect(action_logs.count).to eq 3
+    end
+  end
+
   describe 'validatiions' do
     it 'has a valid fabricator' do
       report = Fabricate(:report)