public_link_spec.rb 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. require 'models/application_model_examples'
  4. RSpec.describe PublicLink, type: :model do
  5. it_behaves_like 'ApplicationModel', can_param: { sample_data_attribute: :title }
  6. context 'when validating URLs' do
  7. it 'raises no exception for a valid link' do
  8. expect { create(:public_link) }.not_to raise_error
  9. end
  10. it 'raises an exception for an invalid link' do
  11. expect { create(:public_link, link: 'invalid') }.to raise_error(Exceptions::UnprocessableEntity)
  12. end
  13. end
  14. context 'when updating prios' do
  15. let(:links) do
  16. first_link = create(:public_link, prio: 1)
  17. second_link = create(:public_link, prio: 2)
  18. third_link = create(:public_link, prio: 3)
  19. {
  20. first: first_link,
  21. second: second_link,
  22. third: third_link,
  23. }
  24. end
  25. it 'rearranges the prios', :aggregate_failures do
  26. links[:third].update!(prio: 1)
  27. link_ids = described_class.reorder(prio: :asc).pluck(:id)
  28. expect(link_ids.first).to eq(links[:third].id)
  29. expect(link_ids.second).to eq(links[:first].id)
  30. expect(link_ids.third).to eq(links[:second].id)
  31. end
  32. end
  33. end