issue_4543_organization_vip_spec.rb 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Issue4543OrganizationVip, db_strategy: :reset, type: :db_migration do
  4. before do
  5. # Clean-up vip field of schema
  6. ObjectManager::Attribute.remove(object_lookup_id: ObjectLookup.by_name('Organization'), name: 'vip', force: true)
  7. ObjectManager::Attribute.migration_execute(false)
  8. # Create custom vip attribute
  9. vip_attribute
  10. ObjectManager::Attribute.migration_execute(false)
  11. end
  12. context "when a non-boolean 'vip' attribute already exists" do
  13. let(:vip_attribute) { create(:object_manager_attribute_select, name: 'vip', object_name: 'Organization') }
  14. it 'renames the existing attribute properly', :aggregate_failures do
  15. migrate
  16. expect(vip_attribute.reload.name).to eq('_vip')
  17. expect(Organization.attribute_names).to include('_vip', 'vip')
  18. end
  19. end
  20. context "when a boolean 'vip' attribute already exists" do
  21. let(:vip_attribute) { create(:object_manager_attribute_boolean, name: 'vip', display: 'Custom VIP', object_name: 'Organization') }
  22. it 'keeps the existing attribute and updates it', :aggregate_failures do
  23. migrate
  24. expect(vip_attribute.reload).to have_attributes(name: 'vip', display: 'VIP', position: 1450)
  25. expect(Organization.attribute_names).to include('vip')
  26. expect(Organization.attribute_names).not_to include('_vip')
  27. end
  28. end
  29. end