issue_2867_footer_header_public_link_spec.rb 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Issue2867FooterHeaderPublicLink, db_strategy: :reset, type: :db_migration do
  4. before { without_column(table, column: column) }
  5. let(:table) { :knowledge_base_menu_items }
  6. let(:column) { :location }
  7. it 'adds an index' do
  8. expect { migrate }.to change { index_exists?(table, column) }.to(true)
  9. end
  10. it 'sets no default' do
  11. expect { migrate }
  12. .not_to change {
  13. KnowledgeBase::MenuItem.reset_column_information
  14. KnowledgeBase::MenuItem.column_defaults['location']
  15. }.from(nil)
  16. end
  17. it 'sets location for existing items' do
  18. # create menu item without touching location column
  19. menu_item = KnowledgeBase::MenuItem.acts_as_list_no_update do
  20. attrs = attributes_for(:knowledge_base_menu_item)
  21. attrs.delete :location
  22. item = KnowledgeBase::MenuItem.new(attrs)
  23. item.position = 0
  24. item.kb_locale = create(:knowledge_base).kb_locales.first
  25. item.save(validate: false)
  26. item
  27. end
  28. expect { migrate }.to change { menu_item.reload.attributes['location'] }.from(nil).to('header')
  29. end
  30. end