rename_locale_on_users_spec.rb 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe RenameLocaleOnUsers, type: :db_migration do
  4. context 'when custom OMA attribute #locale exists', db_strategy: :reset do
  5. before do
  6. ObjectManager::Attribute.add(
  7. force: true,
  8. object: 'User',
  9. name: 'locale',
  10. display: 'Locale',
  11. data_type: 'select',
  12. data_option: {
  13. 'default' => '',
  14. 'options' => {},
  15. },
  16. active: true,
  17. position: 20,
  18. to_migrate: true,
  19. created_by_id: 1,
  20. updated_by_id: 1,
  21. )
  22. ObjectManager::Attribute.migration_execute
  23. end
  24. it 'renames #locale' do
  25. expect { migrate }
  26. .to change { ActiveRecord::Base.connection.columns('users').map(&:name) }
  27. .to not_include('locale')
  28. .and include('_locale')
  29. expect(ObjectManager::Attribute.exists?(name: 'locale')).to be(false)
  30. expect(ObjectManager::Attribute.exists?(name: '_locale')).to be(true)
  31. end
  32. end
  33. context 'when no #locale attribute exists' do
  34. it 'makes no changes to the "users" table' do
  35. expect { migrate }
  36. .not_to change { ActiveRecord::Base.connection.columns('users') }
  37. end
  38. end
  39. end