Add missing tests for report.rb (#7324)

remotes/1727458204337373841/tmp_refs/heads/signup-info-prompt
Shuhei Kitagawa 2018-05-03 17:42:36 +09:00 committed by Eugen Rochko
parent ad5d3134e4
commit 28b366d065
1 changed files with 95 additions and 0 deletions

View File

@ -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)