reserved_words_per_model_spec.rb 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. # Copyright (C) 2012-2025 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe ReservedWordsPerModel, db_strategy: :reset, type: :db_migration do
  4. let(:attribute) do
  5. ObjectManager::Attribute.add(
  6. attributes_for(
  7. :object_manager_attribute_text,
  8. object_name:,
  9. name: 'article'
  10. ).merge(force: true)
  11. )
  12. ObjectManager::Attribute.migration_execute(false)
  13. ObjectManager::Attribute.get(object: object_name.constantize.to_app_model, name: 'article')
  14. end
  15. before { attribute }
  16. context 'when an attribute called "article" exists in the Ticket model' do
  17. let(:object_name) { 'Ticket' }
  18. it 'renames the attribute to "_article"' do
  19. expect { migrate }.to change { attribute.reload.name }.from('article').to('_article')
  20. end
  21. end
  22. context 'when an attribute called "article" exists in the User model' do
  23. let(:object_name) { 'User' }
  24. it 'does not rename the attribute' do
  25. expect { migrate }.not_to change { attribute.reload.name }
  26. end
  27. end
  28. end