parent
19b4311e8b
commit
96f8070e79
5 changed files with 98 additions and 0 deletions
|
@ -22,5 +22,9 @@ FactoryBot.define do
|
||||||
trait :with_avatar do
|
trait :with_avatar do
|
||||||
avatar { Rack::Test::UploadedFile.new('spec/assets/avatar.png', 'image/png') }
|
avatar { Rack::Test::UploadedFile.new('spec/assets/avatar.png', 'image/png') }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
trait :administrator do
|
||||||
|
role { 'administrator' }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
31
spec/policies/contact_policy_spec.rb
Normal file
31
spec/policies/contact_policy_spec.rb
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe ContactPolicy, type: :policy do
|
||||||
|
subject(:contact_policy) { described_class }
|
||||||
|
|
||||||
|
let(:administrator) { create(:user, :administrator) }
|
||||||
|
let(:agent) { create(:user) }
|
||||||
|
let(:contact) { create(:contact) }
|
||||||
|
|
||||||
|
permissions :index?, :show?, :update? do
|
||||||
|
context 'when administrator' do
|
||||||
|
it { expect(contact_policy).to permit(administrator, contact) }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when agent' do
|
||||||
|
it { expect(contact_policy).not_to permit(agent, contact) }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
permissions :create? do
|
||||||
|
context 'when administrator' do
|
||||||
|
it { expect(contact_policy).to permit(administrator, contact) }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when agent' do
|
||||||
|
it { expect(contact_policy).to permit(agent, contact) }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
31
spec/policies/inbox_policy_spec.rb
Normal file
31
spec/policies/inbox_policy_spec.rb
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe InboxPolicy, type: :policy do
|
||||||
|
subject(:inbox_policy) { described_class }
|
||||||
|
|
||||||
|
let(:administrator) { create(:user, :administrator) }
|
||||||
|
let(:agent) { create(:user) }
|
||||||
|
let(:inbox) { create(:inbox) }
|
||||||
|
|
||||||
|
permissions :create?, :destroy? do
|
||||||
|
context 'when administrator' do
|
||||||
|
it { expect(inbox_policy).to permit(administrator, inbox) }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when agent' do
|
||||||
|
it { expect(inbox_policy).not_to permit(agent, inbox) }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
permissions :index? do
|
||||||
|
context 'when administrator' do
|
||||||
|
it { expect(inbox_policy).to permit(administrator, inbox) }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when agent' do
|
||||||
|
it { expect(inbox_policy).to permit(agent, inbox) }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
31
spec/policies/user_policy_spec.rb
Normal file
31
spec/policies/user_policy_spec.rb
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe UserPolicy, type: :policy do
|
||||||
|
subject(:user_policy) { described_class }
|
||||||
|
|
||||||
|
let(:administrator) { create(:user, :administrator) }
|
||||||
|
let(:agent) { create(:user) }
|
||||||
|
let(:user) { create(:user) }
|
||||||
|
|
||||||
|
permissions :create?, :update?, :destroy? do
|
||||||
|
context 'when administrator' do
|
||||||
|
it { expect(user_policy).to permit(administrator, user) }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when agent' do
|
||||||
|
it { expect(user_policy).not_to permit(agent, user) }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
permissions :index? do
|
||||||
|
context 'when administrator' do
|
||||||
|
it { expect(user_policy).to permit(administrator, user) }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when agent' do
|
||||||
|
it { expect(user_policy).to permit(agent, user) }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -4,6 +4,7 @@ require File.expand_path('../config/environment', __dir__)
|
||||||
# Prevent database truncation if the environment is production
|
# Prevent database truncation if the environment is production
|
||||||
abort('The Rails environment is running in production mode!') if Rails.env.production?
|
abort('The Rails environment is running in production mode!') if Rails.env.production?
|
||||||
require 'rspec/rails'
|
require 'rspec/rails'
|
||||||
|
require 'pundit/rspec'
|
||||||
|
|
||||||
# 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!
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue