user_context_spec.rb 955 B

12345678910111213141516171819202122232425
  1. require 'rails_helper'
  2. RSpec.describe UserContext do
  3. subject(:user_context) { described_class.new(user, token) }
  4. describe '#permissions?' do
  5. context 'when user with ticket.agent permission' do
  6. let(:user) { create(:user, roles: [create(:agent_role)]) }
  7. let(:token) { nil }
  8. it { is_expected.to be_permissions('ticket.agent') }
  9. it { is_expected.not_to be_permissions('admin') }
  10. end
  11. # https://github.com/zammad/zammad/issues/3186
  12. context 'when user with ticket.agent permission and token created by user who doesn\'t' do
  13. let(:user) { create(:user, roles: [create(:agent_role)]) }
  14. let(:token_owner) { create(:user, roles: [create(:role, :admin)]) }
  15. let(:token) { create(:token, user: token_owner, preferences: { permission: %w[ticket.agent] }) }
  16. it { is_expected.to be_permissions('ticket.agent') }
  17. it { is_expected.not_to be_permissions('admin') }
  18. end
  19. end
  20. end