backup_policy_spec.rb 968 B

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