issue_2867_footer_header_public_link_spec.rb 1.1 KB

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