check_for_object_attributes_spec.rb 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. require 'rails_helper'
  2. RSpec.describe CheckForObjectAttributes, type: :db_migration do
  3. it 'performs no action for new systems', system_init_done: false do
  4. migrate do |instance|
  5. expect(instance).not_to receive(:attributes)
  6. end
  7. end
  8. context 'valid [:data_option]' do
  9. it 'does not change converted text attribute' do
  10. attribute = create(:object_manager_attribute_text)
  11. expect do
  12. migrate
  13. end.not_to change {
  14. attribute.reload.data_option
  15. }
  16. end
  17. it 'does not change select attribute' do
  18. attribute = create(:object_manager_attribute_select)
  19. expect do
  20. migrate
  21. end.not_to change {
  22. attribute.reload.data_option
  23. }
  24. end
  25. it 'does not change tree_select attribute' do
  26. attribute = create(:object_manager_attribute_tree_select)
  27. expect do
  28. migrate
  29. end.not_to change {
  30. attribute.reload.data_option
  31. }
  32. end
  33. end
  34. context '[:data_option]' do
  35. it 'ensures an empty Hash' do
  36. attribute = create(:object_manager_attribute_text, data_option: nil)
  37. migrate
  38. attribute.reload
  39. expect(attribute[:data_option]).to be_a(Hash)
  40. end
  41. end
  42. context '[:data_option][:options]' do
  43. it 'ensures an empty Hash' do
  44. attribute = create(:object_manager_attribute_text, data_option: {})
  45. migrate
  46. attribute.reload
  47. expect(attribute[:data_option][:options]).to be_a(Hash)
  48. end
  49. it 'converts String to Hash' do
  50. wrong = {
  51. default: '',
  52. options: '',
  53. relation: '',
  54. null: true
  55. }
  56. attribute = create(:object_manager_attribute_text, data_option: wrong)
  57. migrate
  58. attribute.reload
  59. expect(attribute[:data_option][:options]).to be_a(Hash)
  60. expect(attribute[:data_option][:options]).to be_blank
  61. end
  62. end
  63. context '[:data_option][:relation]' do
  64. it 'ensures an empty String' do
  65. wrong = {
  66. default: '',
  67. options: {},
  68. null: true
  69. }
  70. attribute = create(:object_manager_attribute_text, data_option: wrong)
  71. migrate
  72. attribute.reload
  73. expect(attribute[:data_option][:relation]).to be_a(String)
  74. end
  75. it 'converts Hash to String' do
  76. wrong = {
  77. default: '',
  78. options: {},
  79. relation: {},
  80. null: true
  81. }
  82. attribute = create(:object_manager_attribute_text, data_option: wrong)
  83. migrate
  84. attribute.reload
  85. expect(attribute[:data_option][:relation]).to be_a(String)
  86. expect(attribute[:data_option][:relation]).to be_blank
  87. end
  88. end
  89. end