This repository has been archived on 2024-06-09. You can view files and clone it, but cannot push or open issues/pull-requests.
2018-12-19 18:24:15 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
require 'pundit/rspec'
|
|
|
|
|
|
|
|
RSpec.describe BackupPolicy do
|
|
|
|
let(:subject) { described_class }
|
2022-01-28 00:46:42 +01:00
|
|
|
let(:john) { Fabricate(:account) }
|
2018-12-19 18:24:15 +01:00
|
|
|
|
|
|
|
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
|