Test Pundit policies
This commit is contained in:
parent
238d7833c6
commit
75e568e075
11 changed files with 34 additions and 134 deletions
3
Gemfile
3
Gemfile
|
@ -204,4 +204,7 @@ group :test do
|
||||||
# It aims to mimic the behaviour of a real user,
|
# It aims to mimic the behaviour of a real user,
|
||||||
# and as such interacts with the HTML of the application.
|
# and as such interacts with the HTML of the application.
|
||||||
gem 'selenium-webdriver', '~> 3.14'
|
gem 'selenium-webdriver', '~> 3.14'
|
||||||
|
|
||||||
|
# A set of RSpec matchers for testing Pundit authorization policies.
|
||||||
|
gem 'pundit-matchers', '~> 1.6'
|
||||||
end
|
end
|
||||||
|
|
|
@ -250,6 +250,8 @@ GEM
|
||||||
puma (3.12.0)
|
puma (3.12.0)
|
||||||
pundit (2.0.0)
|
pundit (2.0.0)
|
||||||
activesupport (>= 3.0.0)
|
activesupport (>= 3.0.0)
|
||||||
|
pundit-matchers (1.6.0)
|
||||||
|
rspec-rails (>= 3.0.0)
|
||||||
rack (2.0.6)
|
rack (2.0.6)
|
||||||
rack-attack (5.4.2)
|
rack-attack (5.4.2)
|
||||||
rack (>= 1.0, < 3)
|
rack (>= 1.0, < 3)
|
||||||
|
@ -459,6 +461,7 @@ DEPENDENCIES
|
||||||
pry-rails (~> 0.3)
|
pry-rails (~> 0.3)
|
||||||
puma (~> 3.11)
|
puma (~> 3.11)
|
||||||
pundit (~> 2.0)
|
pundit (~> 2.0)
|
||||||
|
pundit-matchers (~> 1.6)
|
||||||
rack-attack (~> 5.4)
|
rack-attack (~> 5.4)
|
||||||
rails (~> 5.2.1)
|
rails (~> 5.2.1)
|
||||||
rails-erd (~> 1.5)
|
rails-erd (~> 1.5)
|
||||||
|
|
|
@ -3,23 +3,5 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe <%= class_name %>Policy do
|
RSpec.describe <%= class_name %>Policy do
|
||||||
permissions '.scope' do
|
pending "add some examples to (or delete) #{__FILE__}"
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
|
||||||
end
|
|
||||||
|
|
||||||
permissions :show? do
|
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
|
||||||
end
|
|
||||||
|
|
||||||
permissions :create? do
|
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
|
||||||
end
|
|
||||||
|
|
||||||
permissions :update? do
|
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
|
||||||
end
|
|
||||||
|
|
||||||
permissions :destroy? do
|
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
20
spec/policies/application_policy_spec.rb
Normal file
20
spec/policies/application_policy_spec.rb
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe ApplicationPolicy do
|
||||||
|
subject { described_class.new context, record }
|
||||||
|
|
||||||
|
let :context do
|
||||||
|
described_class::Context.new account: account, guest_account: guest_account
|
||||||
|
end
|
||||||
|
|
||||||
|
let(:account) { create :superuser_account }
|
||||||
|
let(:guest_account) { create :guest_account }
|
||||||
|
|
||||||
|
let(:record) { nil }
|
||||||
|
|
||||||
|
it do
|
||||||
|
is_expected.to forbid_actions %i[index show new create edit update destroy]
|
||||||
|
end
|
||||||
|
end
|
|
@ -3,23 +3,5 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe MembershipAppPolicy do
|
RSpec.describe MembershipAppPolicy do
|
||||||
permissions '.scope' do
|
pending "add some examples to (or delete) #{__FILE__}"
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
|
||||||
end
|
|
||||||
|
|
||||||
permissions :show? do
|
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
|
||||||
end
|
|
||||||
|
|
||||||
permissions :create? do
|
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
|
||||||
end
|
|
||||||
|
|
||||||
permissions :update? do
|
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
|
||||||
end
|
|
||||||
|
|
||||||
permissions :destroy? do
|
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,23 +3,5 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe Settings::AccountTelegramContactPolicy do
|
RSpec.describe Settings::AccountTelegramContactPolicy do
|
||||||
permissions '.scope' do
|
pending "add some examples to (or delete) #{__FILE__}"
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
|
||||||
end
|
|
||||||
|
|
||||||
permissions :show? do
|
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
|
||||||
end
|
|
||||||
|
|
||||||
permissions :create? do
|
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
|
||||||
end
|
|
||||||
|
|
||||||
permissions :update? do
|
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
|
||||||
end
|
|
||||||
|
|
||||||
permissions :destroy? do
|
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,23 +3,5 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe Staff::PassportConfirmationPolicy do
|
RSpec.describe Staff::PassportConfirmationPolicy do
|
||||||
permissions '.scope' do
|
pending "add some examples to (or delete) #{__FILE__}"
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
|
||||||
end
|
|
||||||
|
|
||||||
permissions :show? do
|
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
|
||||||
end
|
|
||||||
|
|
||||||
permissions :create? do
|
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
|
||||||
end
|
|
||||||
|
|
||||||
permissions :update? do
|
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
|
||||||
end
|
|
||||||
|
|
||||||
permissions :destroy? do
|
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,23 +3,5 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe Staff::PassportPolicy do
|
RSpec.describe Staff::PassportPolicy do
|
||||||
permissions '.scope' do
|
pending "add some examples to (or delete) #{__FILE__}"
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
|
||||||
end
|
|
||||||
|
|
||||||
permissions :show? do
|
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
|
||||||
end
|
|
||||||
|
|
||||||
permissions :create? do
|
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
|
||||||
end
|
|
||||||
|
|
||||||
permissions :update? do
|
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
|
||||||
end
|
|
||||||
|
|
||||||
permissions :destroy? do
|
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,23 +3,5 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe Staff::TelegramBotPolicy do
|
RSpec.describe Staff::TelegramBotPolicy do
|
||||||
permissions '.scope' do
|
pending "add some examples to (or delete) #{__FILE__}"
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
|
||||||
end
|
|
||||||
|
|
||||||
permissions :show? do
|
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
|
||||||
end
|
|
||||||
|
|
||||||
permissions :create? do
|
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
|
||||||
end
|
|
||||||
|
|
||||||
permissions :update? do
|
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
|
||||||
end
|
|
||||||
|
|
||||||
permissions :destroy? do
|
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,23 +3,5 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe Staff::TelegramChatPolicy do
|
RSpec.describe Staff::TelegramChatPolicy do
|
||||||
permissions '.scope' do
|
pending "add some examples to (or delete) #{__FILE__}"
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
|
||||||
end
|
|
||||||
|
|
||||||
permissions :show? do
|
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
|
||||||
end
|
|
||||||
|
|
||||||
permissions :create? do
|
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
|
||||||
end
|
|
||||||
|
|
||||||
permissions :update? do
|
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
|
||||||
end
|
|
||||||
|
|
||||||
permissions :destroy? do
|
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,7 +15,7 @@ require 'rspec/rails'
|
||||||
|
|
||||||
# Add additional requires below this line. Rails is not loaded until this point!
|
# Add additional requires below this line. Rails is not loaded until this point!
|
||||||
|
|
||||||
require 'pundit/rspec'
|
require 'pundit/matchers'
|
||||||
|
|
||||||
# Requires supporting ruby files with custom matchers and macros, etc, in
|
# Requires supporting ruby files with custom matchers and macros, etc, in
|
||||||
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
|
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
|
||||||
|
|
Reference in a new issue