issue_5083_chat_permission_spec.rb 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Issue5083ChatPermission, type: :db_migration do
  4. let(:role_with_chat_permission) { create(:role) }
  5. let(:role_without_chat_permission) { create(:role) }
  6. before do
  7. # undisable chat permission
  8. Permission.create_or_update(
  9. name: 'chat',
  10. note: __('Access to %s'),
  11. preferences: {
  12. translations: [__('Chat')],
  13. },
  14. )
  15. role_with_chat_permission.permissions << Permission.find_by(name: 'chat')
  16. role_without_chat_permission
  17. # reset original state
  18. Permission.create_or_update(
  19. name: 'chat',
  20. note: __('Access to %s'),
  21. preferences: {
  22. translations: [__('Chat')],
  23. disabled: true,
  24. },
  25. )
  26. migrate
  27. end
  28. it 'does migrate role with chat permission', :aggregate_failures do
  29. expect(role_with_chat_permission.reload.permissions).not_to include(Permission.find_by(name: 'chat'))
  30. expect(role_with_chat_permission.reload.permissions).to include(Permission.find_by(name: 'chat.agent'))
  31. end
  32. it 'does not touch role without chat permission', :aggregate_failures do
  33. expect(role_without_chat_permission.reload.permissions).not_to include(Permission.find_by(name: 'chat'))
  34. expect(role_without_chat_permission.reload.permissions).not_to include(Permission.find_by(name: 'chat.agent'))
  35. end
  36. end