闭社主体 forked from https://github.com/tootsuite/mastodon
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.

45 lines
979 B

  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(:user).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