backup_policy_spec.rb 974 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. require 'pundit/rspec'
  4. RSpec.describe BackupPolicy do
  5. let(:subject) { described_class }
  6. let(:john) { Fabricate(:account) }
  7. permissions :create? do
  8. context 'not user_signed_in?' do
  9. it 'denies' do
  10. expect(subject).to_not permit(nil, Backup)
  11. end
  12. end
  13. context 'user_signed_in?' do
  14. context 'no backups' do
  15. it 'permits' do
  16. expect(subject).to permit(john, Backup)
  17. end
  18. end
  19. context 'backups are too old' do
  20. it 'permits' do
  21. travel(-8.days) do
  22. Fabricate(:backup, user: john.user)
  23. end
  24. expect(subject).to permit(john, Backup)
  25. end
  26. end
  27. context 'backups are newer' do
  28. it 'denies' do
  29. travel(-3.days) do
  30. Fabricate(:backup, user: john.user)
  31. end
  32. expect(subject).to_not permit(john, Backup)
  33. end
  34. end
  35. end
  36. end
  37. end