issue_2867_footer_header_public_link_spec.rb 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. require 'rails_helper'
  2. RSpec.describe Issue2867FooterHeaderPublicLink, type: :db_migration do
  3. self.use_transactional_tests = false # see comments on #without_index method
  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