1
0
Fork 0

Add specs for Staff::TelegramBotPolicy

This commit is contained in:
Alex Kotov 2018-12-13 08:20:56 +05:00
parent 919b03cdc7
commit 64e0e082b4
No known key found for this signature in database
GPG key ID: 4E831250F47DE154
3 changed files with 45 additions and 3 deletions

View file

@ -3,5 +3,41 @@
require 'rails_helper'
RSpec.describe Staff::TelegramBotPolicy do
pending "add some examples to (or delete) #{__FILE__}"
subject { described_class.new account, record }
let(:record) { create :telegram_bot }
context 'when no account is authenticated' do
let(:account) { nil }
it { is_expected.to forbid_actions %i[index show destroy] }
it { is_expected.to forbid_new_and_create_actions }
it { is_expected.to forbid_edit_and_update_actions }
end
context 'when guest account is authenticated' do
let(:account) { create :guest_account }
it { is_expected.to forbid_actions %i[index show destroy] }
it { is_expected.to forbid_new_and_create_actions }
it { is_expected.to forbid_edit_and_update_actions }
end
context 'when usual account is authenticated' do
let(:account) { create :usual_account }
it { is_expected.to forbid_actions %i[index show destroy] }
it { is_expected.to forbid_new_and_create_actions }
it { is_expected.to forbid_edit_and_update_actions }
end
context 'when superuser account is authenticated' do
let(:account) { create :superuser_account }
it { is_expected.to permit_actions %i[index show] }
it { is_expected.to forbid_new_and_create_actions }
it { is_expected.to forbid_edit_and_update_actions }
it { is_expected.to forbid_action :destroy }
end
end

View file

@ -15,8 +15,6 @@ require 'rspec/rails'
# Add additional requires below this line. Rails is not loaded until this point!
require 'pundit/matchers'
# Requires supporting ruby files with custom matchers and macros, etc, in
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
# run as spec files by default. This means that files in spec/support that end
@ -35,6 +33,7 @@ require_relative 'support/faker'
require_relative 'support/factory_bot'
require_relative 'support/database_cleaner'
require_relative 'support/devise'
require_relative 'support/pundit'
# Checks for pending migrations and applies them before tests are run.
# If you are not using ActiveRecord, you can remove these lines.

7
spec/support/pundit.rb Normal file
View file

@ -0,0 +1,7 @@
# frozen_string_literal: true
require 'pundit/matchers'
Pundit::Matchers.configure do |config|
config.user_alias = :account
end