backup_policy_spec.rb 991 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. require 'pundit/rspec'
  4. RSpec.describe BackupPolicy do
  5. subject { described_class }
  6. let(:john) { Fabricate(:account) }
  7. permissions :create? do
  8. context 'when not user_signed_in?' do
  9. it 'denies' do
  10. expect(subject).to_not permit(nil, Backup)
  11. end
  12. end
  13. context 'when user_signed_in?' do
  14. context 'with no backups' do
  15. it 'permits' do
  16. expect(subject).to permit(john, Backup)
  17. end
  18. end
  19. context 'when 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 'when 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