2018-12-19 12:24:15 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
require 'pundit/rspec'
|
|
|
|
|
|
|
|
RSpec.describe BackupPolicy do
|
2023-07-12 03:49:33 -04:00
|
|
|
subject { described_class }
|
|
|
|
|
|
|
|
let(:john) { Fabricate(:account) }
|
2018-12-19 12:24:15 -05:00
|
|
|
|
|
|
|
permissions :create? do
|
2023-05-03 23:49:08 -04:00
|
|
|
context 'when not user_signed_in?' do
|
2018-12-19 12:24:15 -05:00
|
|
|
it 'denies' do
|
|
|
|
expect(subject).to_not permit(nil, Backup)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-03 23:49:08 -04:00
|
|
|
context 'when user_signed_in?' do
|
|
|
|
context 'with no backups' do
|
2018-12-19 12:24:15 -05:00
|
|
|
it 'permits' do
|
|
|
|
expect(subject).to permit(john, Backup)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-03 23:49:08 -04:00
|
|
|
context 'when backups are too old' do
|
2018-12-19 12:24:15 -05:00
|
|
|
it 'permits' do
|
|
|
|
travel(-8.days) do
|
|
|
|
Fabricate(:backup, user: john.user)
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(subject).to permit(john, Backup)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-03 23:49:08 -04:00
|
|
|
context 'when backups are newer' do
|
2018-12-19 12:24:15 -05:00
|
|
|
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
|