You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.6 KiB

  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe StatusFinder do
  4. include RoutingHelper
  5. describe '#status' do
  6. subject { described_class.new(url) }
  7. context 'with a status url' do
  8. let(:status) { Fabricate(:status) }
  9. let(:url) { short_account_status_url(account_username: status.account.username, id: status.id) }
  10. it 'finds the stream entry' do
  11. expect(subject.status).to eq(status)
  12. end
  13. it 'raises an error if action is not :show' do
  14. recognized = Rails.application.routes.recognize_path(url)
  15. expect(recognized).to receive(:[]).with(:action).and_return(:create)
  16. expect(Rails.application.routes).to receive(:recognize_path).with(url).and_return(recognized)
  17. expect { subject.status }.to raise_error(ActiveRecord::RecordNotFound)
  18. end
  19. end
  20. context 'with a remote url even if id exists on local' do
  21. let(:status) { Fabricate(:status) }
  22. let(:url) { "https://example.com/users/test/statuses/#{status.id}" }
  23. it 'raises an error' do
  24. expect { subject.status }.to raise_error(ActiveRecord::RecordNotFound)
  25. end
  26. end
  27. context 'with a plausible url' do
  28. let(:url) { 'https://example.com/users/test/updates/123/embed' }
  29. it 'raises an error' do
  30. expect { subject.status }.to raise_error(ActiveRecord::RecordNotFound)
  31. end
  32. end
  33. context 'with an unrecognized url' do
  34. let(:url) { 'https://example.com/about' }
  35. it 'raises an error' do
  36. expect { subject.status }.to raise_error(ActiveRecord::RecordNotFound)
  37. end
  38. end
  39. end
  40. end