overview_spec.rb 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. require 'rails_helper'
  2. RSpec.describe Overview, type: :model do
  3. it_behaves_like 'ApplicationModel', can_assets: { associations: :users, selectors: :condition }
  4. context 'link generation' do
  5. it 'generates from name' do
  6. overview = create(:overview, name: 'Not Shown Admin 2')
  7. expect(overview.link).to eq('not_shown_admin_2')
  8. end
  9. it 'ensures uniquenes' do
  10. overview1, overview2, overview3 = create_list(:overview, 3, name: 'Übersicht')
  11. expect(overview1.link).not_to eq(overview2.link)
  12. expect(overview1.link).not_to eq(overview3.link)
  13. expect(overview2.link).not_to eq(overview3.link)
  14. end
  15. context 'given link' do
  16. it 'keeps on create' do
  17. overview = create(:overview, name: 'Übersicht', link: 'my_overview')
  18. expect(overview.link).to eq('my_overview')
  19. end
  20. it 'keeps on update' do
  21. overview = create(:overview, name: 'Übersicht')
  22. overview.update!(link: 'my_overview_2')
  23. expect(overview.link).to eq('my_overview_2')
  24. end
  25. end
  26. context 'URL save' do
  27. it 'handles umlauts' do
  28. overview = create(:overview, name: 'Übersicht')
  29. expect(overview.link).to eq('ubersicht')
  30. end
  31. it 'handles spaces' do
  32. overview = create(:overview, name: " Meine Übersicht \n")
  33. expect(overview.link).to eq('meine_ubersicht')
  34. end
  35. it 'handles special chars' do
  36. overview = create(:overview, name: 'Д дФ ф')
  37. expect(overview.link).to match(/^\d{1,3}$/)
  38. end
  39. it 'removes special char fallback if possible' do
  40. overview = create(:overview, name: ' Д дФ ф abc ')
  41. expect(overview.link).to eq('abc')
  42. end
  43. end
  44. end
  45. describe '#rearrangement' do
  46. it 'rearranges prio of other overviews on prio change' do
  47. overview1 = create(:overview, prio: 1)
  48. overview2 = create(:overview, prio: 2)
  49. overview3 = create(:overview, prio: 3)
  50. overview2.update!(prio: 3)
  51. overviews = described_class.all.order(prio: :asc).pluck(:id)
  52. expect(overviews.first).to eq(overview1.id)
  53. expect(overviews.second).to eq(overview3.id)
  54. expect(overviews.third).to eq(overview2.id)
  55. end
  56. end
  57. end