rename_locale_on_users_spec.rb 1.2 KB

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