about summary refs log tree commit diff
path: root/spec/policies/backup_policy_spec.rb
blob: 80407e12f850de0ab7f99e9d28b8232daa80db9f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# frozen_string_literal: true

require 'rails_helper'
require 'pundit/rspec'

RSpec.describe BackupPolicy do
  let(:subject) { described_class }
  let(:john)    { Fabricate(:user).account }

  permissions :create? do
    context 'not user_signed_in?' do
      it 'denies' do
        expect(subject).to_not permit(nil, Backup)
      end
    end

    context 'user_signed_in?' do
      context 'no backups' do
        it 'permits' do
          expect(subject).to permit(john, Backup)
        end
      end

      context 'backups are too old' do
        it 'permits' do
          travel(-8.days) do
            Fabricate(:backup, user: john.user)
          end

          expect(subject).to permit(john, Backup)
        end
      end

      context 'backups are newer' do
        it 'denies' do
          travel(-3.days) do
            Fabricate(:backup, user: john.user)
          end

          expect(subject).to_not permit(john, Backup)
        end
      end
    end
  end
end