update_user_attributes_spec.rb 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe UpdateUserAttributes, type: :db_migration do
  4. context 'with email attribute' do
  5. let(:object_manager_attribute) do
  6. ObjectManager::Attribute
  7. .find_by(name: 'email', object_lookup_id: ObjectLookup.by_name('User'))
  8. end
  9. before do
  10. object_manager_attribute.screens = {
  11. signup: { '-all-' => { 'null' => true } },
  12. invite_agent: { '-all-' => { 'null' => true } },
  13. invite_customer: { '-all-' => { 'null' => true } },
  14. }
  15. object_manager_attribute.save!
  16. end
  17. it 'makes field required', system_init_done: true do
  18. expect { migrate }
  19. .to change { object_manager_attribute.reload.screens }
  20. .to(
  21. include(
  22. signup: { '-all-' => { 'null' => false } },
  23. invite_agent: { '-all-' => { 'null' => false } },
  24. invite_customer: { '-all-' => { 'null' => false } },
  25. )
  26. )
  27. end
  28. end
  29. context 'with role_ids attribute' do
  30. let(:object_manager_attribute) do
  31. ObjectManager::Attribute
  32. .find_by(name: 'role_ids', object_lookup_id: ObjectLookup.by_name('User'))
  33. end
  34. before do
  35. object_manager_attribute.data_option = { other: 'attr' }
  36. object_manager_attribute.save!
  37. end
  38. it 'adds relation data option', system_init_done: true do
  39. expect { migrate }
  40. .to change { object_manager_attribute.reload.data_option }
  41. .to(include(relation: 'Role', other: 'attr'))
  42. end
  43. end
  44. context 'with group_ids attribute' do
  45. let(:object_manager_attribute) do
  46. ObjectManager::Attribute
  47. .find_by(name: 'group_ids', object_lookup_id: ObjectLookup.by_name('User'))
  48. end
  49. before do
  50. object_manager_attribute.screens = { invite_agent: { '-all-' => { 'null' => false } } }
  51. object_manager_attribute.save!
  52. end
  53. it 'makes field required', system_init_done: true do
  54. expect { migrate }
  55. .to change { object_manager_attribute.reload.screens }
  56. .to(
  57. include(
  58. invite_agent: { '-all-' => { 'null' => true } },
  59. )
  60. )
  61. end
  62. end
  63. end