object_spec.rb 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. require 'rails_helper'
  2. RSpec.describe ObjectManager::Object do
  3. describe 'attribute permissions', db_strategy: :reset do
  4. let(:user) do
  5. create(:user, roles: [role_attribute_permissions])
  6. end
  7. let(:attribute) { described_class.new('Ticket').attributes(user).detect { |attribute| attribute[:name] == attribute_name } }
  8. let(:role_attribute_permissions) do
  9. create(:role).tap do |role|
  10. role.permission_grant('admin.organization')
  11. role.permission_grant('ticket.agent')
  12. end
  13. end
  14. let(:attribute_name) { 'example_attribute' }
  15. before do
  16. create(:object_manager_attribute_text, name: attribute_name, screens: screens)
  17. ObjectManager::Attribute.migration_execute
  18. end
  19. context 'when true and false values for show exist' do
  20. let(:screens) do
  21. {
  22. create: {
  23. 'admin.organization': {
  24. shown: true
  25. },
  26. 'ticket.agent': {
  27. shown: false
  28. }
  29. }
  30. }
  31. end
  32. it 'uses true' do
  33. expect(attribute[:screen]['create']['shown']).to be true
  34. end
  35. end
  36. context 'when -all- is present' do
  37. let(:screens) do
  38. {
  39. create: {
  40. '-all-': {
  41. shown: true
  42. },
  43. 'admin.organization': {
  44. shown: false
  45. },
  46. 'ticket.agent': {
  47. shown: false
  48. }
  49. }
  50. }
  51. end
  52. it 'takes its values into account' do
  53. expect(attribute[:screen]['create']['shown']).to be true
  54. end
  55. end
  56. context 'when non boolean values are present' do
  57. let(:screens) do
  58. {
  59. create: {
  60. '-all-': {
  61. shown: true,
  62. item_class: 'column'
  63. },
  64. 'admin.organization': {
  65. shown: false
  66. },
  67. 'ticket.agent': {
  68. shown: false
  69. }
  70. }
  71. }
  72. end
  73. it 'takes these values into account' do
  74. expect(attribute[:screen]['create']['item_class']).to eq('column')
  75. end
  76. end
  77. context 'when agent is also customer' do
  78. let(:user) { create(:agent_and_customer) }
  79. let(:screens) do
  80. {
  81. create: {
  82. 'ticket.customer': {
  83. filter: [2, 4]
  84. },
  85. 'ticket.agent': {
  86. filter: [3, 5]
  87. }
  88. }
  89. }
  90. end
  91. it 'prefers agent over customer permissions' do
  92. expect(attribute[:screen]['create']['filter']).to eq([3, 5])
  93. end
  94. end
  95. end
  96. end