appeal_spec.rb 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe Appeal do
  4. describe 'Validations' do
  5. subject { Fabricate.build :appeal, strike: Fabricate(:account_warning) }
  6. it { is_expected.to validate_length_of(:text).is_at_most(described_class::TEXT_LENGTH_LIMIT) }
  7. context 'with a strike created too long ago' do
  8. let(:strike) { Fabricate.build :account_warning, created_at: 100.days.ago }
  9. it { is_expected.to_not allow_values(strike).for(:strike).against(:base).on(:create) }
  10. end
  11. end
  12. describe 'Query methods' do
  13. describe '#pending?' do
  14. subject { Fabricate.build :appeal, approved_at:, rejected_at: }
  15. context 'with not approved and not rejected' do
  16. let(:approved_at) { nil }
  17. let(:rejected_at) { nil }
  18. it { expect(subject).to be_pending }
  19. end
  20. context 'with approved and rejected' do
  21. let(:approved_at) { 1.day.ago }
  22. let(:rejected_at) { 1.day.ago }
  23. it { expect(subject).to_not be_pending }
  24. end
  25. context 'with approved and not rejected' do
  26. let(:approved_at) { 1.day.ago }
  27. let(:rejected_at) { nil }
  28. it { expect(subject).to_not be_pending }
  29. end
  30. context 'with not approved and rejected' do
  31. let(:approved_at) { nil }
  32. let(:rejected_at) { 1.day.ago }
  33. it { expect(subject).to_not be_pending }
  34. end
  35. end
  36. describe '#approved?' do
  37. subject { Fabricate.build :appeal, approved_at: }
  38. context 'with not approved' do
  39. let(:approved_at) { nil }
  40. it { expect(subject).to_not be_approved }
  41. end
  42. context 'with approved' do
  43. let(:approved_at) { 1.day.ago }
  44. it { expect(subject).to be_approved }
  45. end
  46. end
  47. describe '#rejected?' do
  48. subject { Fabricate.build :appeal, rejected_at: }
  49. context 'with not rejected' do
  50. let(:rejected_at) { nil }
  51. it { expect(subject).to_not be_rejected }
  52. end
  53. context 'with rejected' do
  54. let(:rejected_at) { 1.day.ago }
  55. it { expect(subject).to be_rejected }
  56. end
  57. end
  58. end
  59. describe 'Scopes' do
  60. describe '.approved' do
  61. let(:approved_appeal) { Fabricate(:appeal, approved_at: 10.days.ago) }
  62. let(:not_approved_appeal) { Fabricate(:appeal, approved_at: nil) }
  63. it 'finds the correct records' do
  64. results = described_class.approved
  65. expect(results).to eq([approved_appeal])
  66. end
  67. end
  68. describe '.rejected' do
  69. let(:rejected_appeal) { Fabricate(:appeal, rejected_at: 10.days.ago) }
  70. let(:not_rejected_appeal) { Fabricate(:appeal, rejected_at: nil) }
  71. it 'finds the correct records' do
  72. results = described_class.rejected
  73. expect(results).to eq([rejected_appeal])
  74. end
  75. end
  76. describe '.pending' do
  77. let(:approved_appeal) { Fabricate(:appeal, approved_at: 10.days.ago) }
  78. let(:rejected_appeal) { Fabricate(:appeal, rejected_at: 10.days.ago) }
  79. let(:pending_appeal) { Fabricate(:appeal, rejected_at: nil, approved_at: nil) }
  80. it 'finds the correct records' do
  81. results = described_class.pending
  82. expect(results).to eq([pending_appeal])
  83. end
  84. end
  85. end
  86. end