Add specs for policies (#9591)
* Add spec for RelayPolicy * Add specs for SubscriptionPolicy * Add specs for SettingsPolicy * Add specs for TagPolicy * Add specs for ReportPolicy
This commit is contained in:
parent
8cf484e5a7
commit
6aeb34dc4c
5 changed files with 120 additions and 0 deletions
24
spec/policies/relay_policy_spec.rb
Normal file
24
spec/policies/relay_policy_spec.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
require 'pundit/rspec'
|
||||
|
||||
RSpec.describe RelayPolicy do
|
||||
let(:subject) { described_class }
|
||||
let(:admin) { Fabricate(:user, admin: true).account }
|
||||
let(:john) { Fabricate(:user).account }
|
||||
|
||||
permissions :update? do
|
||||
context 'admin?' do
|
||||
it 'permits' do
|
||||
expect(subject).to permit(admin, Relay)
|
||||
end
|
||||
end
|
||||
|
||||
context '!admin?' do
|
||||
it 'denies' do
|
||||
expect(subject).to_not permit(john, Relay)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
24
spec/policies/report_policy_spec.rb
Normal file
24
spec/policies/report_policy_spec.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
require 'pundit/rspec'
|
||||
|
||||
RSpec.describe ReportPolicy do
|
||||
let(:subject) { described_class }
|
||||
let(:admin) { Fabricate(:user, admin: true).account }
|
||||
let(:john) { Fabricate(:user).account }
|
||||
|
||||
permissions :update?, :index?, :show? do
|
||||
context 'staff?' do
|
||||
it 'permits' do
|
||||
expect(subject).to permit(admin, Report)
|
||||
end
|
||||
end
|
||||
|
||||
context '!staff?' do
|
||||
it 'denies' do
|
||||
expect(subject).to_not permit(john, Report)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
24
spec/policies/settings_policy_spec.rb
Normal file
24
spec/policies/settings_policy_spec.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
require 'pundit/rspec'
|
||||
|
||||
RSpec.describe SettingsPolicy do
|
||||
let(:subject) { described_class }
|
||||
let(:admin) { Fabricate(:user, admin: true).account }
|
||||
let(:john) { Fabricate(:user).account }
|
||||
|
||||
permissions :update?, :show? do
|
||||
context 'admin?' do
|
||||
it 'permits' do
|
||||
expect(subject).to permit(admin, Settings)
|
||||
end
|
||||
end
|
||||
|
||||
context '!admin?' do
|
||||
it 'denies' do
|
||||
expect(subject).to_not permit(john, Settings)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
24
spec/policies/subscription_policy_spec.rb
Normal file
24
spec/policies/subscription_policy_spec.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
require 'pundit/rspec'
|
||||
|
||||
RSpec.describe SubscriptionPolicy do
|
||||
let(:subject) { described_class }
|
||||
let(:admin) { Fabricate(:user, admin: true).account }
|
||||
let(:john) { Fabricate(:user).account }
|
||||
|
||||
permissions :index? do
|
||||
context 'admin?' do
|
||||
it 'permits' do
|
||||
expect(subject).to permit(admin, Subscription)
|
||||
end
|
||||
end
|
||||
|
||||
context '!admin?' do
|
||||
it 'denies' do
|
||||
expect(subject).to_not permit(john, Subscription)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
24
spec/policies/tag_policy_spec.rb
Normal file
24
spec/policies/tag_policy_spec.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
require 'pundit/rspec'
|
||||
|
||||
RSpec.describe TagPolicy do
|
||||
let(:subject) { described_class }
|
||||
let(:admin) { Fabricate(:user, admin: true).account }
|
||||
let(:john) { Fabricate(:user).account }
|
||||
|
||||
permissions :index?, :hide?, :unhide? do
|
||||
context 'staff?' do
|
||||
it 'permits' do
|
||||
expect(subject).to permit(admin, Tag)
|
||||
end
|
||||
end
|
||||
|
||||
context '!staff?' do
|
||||
it 'denies' do
|
||||
expect(subject).to_not permit(john, Tag)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue