You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
3.7 KiB

  1. require 'rails_helper'
  2. describe Report do
  3. describe 'statuses' do
  4. it 'returns the statuses for the report' do
  5. status = Fabricate(:status)
  6. _other = Fabricate(:status)
  7. report = Fabricate(:report, status_ids: [status.id])
  8. expect(report.statuses).to eq [status]
  9. end
  10. end
  11. describe 'media_attachments' do
  12. it 'returns media attachments from statuses' do
  13. status = Fabricate(:status)
  14. media_attachment = Fabricate(:media_attachment, status: status)
  15. _other_media_attachment = Fabricate(:media_attachment)
  16. report = Fabricate(:report, status_ids: [status.id])
  17. expect(report.media_attachments).to eq [media_attachment]
  18. end
  19. end
  20. describe 'assign_to_self!' do
  21. subject { report.assigned_account_id }
  22. let(:report) { Fabricate(:report, assigned_account_id: original_account) }
  23. let(:original_account) { Fabricate(:account) }
  24. let(:current_account) { Fabricate(:account) }
  25. before do
  26. report.assign_to_self!(current_account)
  27. end
  28. it 'assigns to a given account' do
  29. is_expected.to eq current_account.id
  30. end
  31. end
  32. describe 'unassign!' do
  33. subject { report.assigned_account_id }
  34. let(:report) { Fabricate(:report, assigned_account_id: account.id) }
  35. let(:account) { Fabricate(:account) }
  36. before do
  37. report.unassign!
  38. end
  39. it 'unassigns' do
  40. is_expected.to be_nil
  41. end
  42. end
  43. describe 'resolve!' do
  44. subject(:report) { Fabricate(:report, action_taken: false, action_taken_by_account_id: nil) }
  45. let(:acting_account) { Fabricate(:account) }
  46. before do
  47. report.resolve!(acting_account)
  48. end
  49. it 'records action taken' do
  50. expect(report).to have_attributes(action_taken: true, action_taken_by_account_id: acting_account.id)
  51. end
  52. end
  53. describe 'unresolve!' do
  54. subject(:report) { Fabricate(:report, action_taken: true, action_taken_by_account_id: acting_account.id) }
  55. let(:acting_account) { Fabricate(:account) }
  56. before do
  57. report.unresolve!
  58. end
  59. it 'unresolves' do
  60. expect(report).to have_attributes(action_taken: false, action_taken_by_account_id: nil)
  61. end
  62. end
  63. describe 'unresolved?' do
  64. subject { report.unresolved? }
  65. let(:report) { Fabricate(:report, action_taken: action_taken) }
  66. context 'if action is taken' do
  67. let(:action_taken) { true }
  68. it { is_expected.to be false }
  69. end
  70. context 'if action not is taken' do
  71. let(:action_taken) { false }
  72. it { is_expected.to be true }
  73. end
  74. end
  75. describe 'history' do
  76. subject(:action_logs) { report.history }
  77. let(:report) { Fabricate(:report, target_account_id: target_account.id, status_ids: [status.id], created_at: 3.days.ago, updated_at: 1.day.ago) }
  78. let(:target_account) { Fabricate(:account) }
  79. let(:status) { Fabricate(:status) }
  80. before do
  81. Fabricate('Admin::ActionLog', target_type: 'Report', account_id: target_account.id, target_id: report.id, created_at: 2.days.ago)
  82. Fabricate('Admin::ActionLog', target_type: 'Account', account_id: target_account.id, target_id: report.target_account_id, created_at: 2.days.ago)
  83. Fabricate('Admin::ActionLog', target_type: 'Status', account_id: target_account.id, target_id: status.id, created_at: 2.days.ago)
  84. end
  85. it 'returns right logs' do
  86. expect(action_logs.count).to eq 3
  87. end
  88. end
  89. describe 'validatiions' do
  90. it 'has a valid fabricator' do
  91. report = Fabricate(:report)
  92. report.valid?
  93. expect(report).to be_valid
  94. end
  95. it 'is invalid if comment is longer than 1000 characters' do
  96. report = Fabricate.build(:report, comment: Faker::Lorem.characters(1001))
  97. report.valid?
  98. expect(report).to model_have_error_on_field(:comment)
  99. end
  100. end
  101. end