status_finder_spec.rb 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.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. allow(recognized).to receive(:[]).with(:action).and_return(:create)
  16. allow(Rails.application.routes).to receive(:recognize_path).with(url).and_return(recognized)
  17. expect { subject.status }.to raise_error(ActiveRecord::RecordNotFound)
  18. expect(Rails.application.routes).to have_received(:recognize_path)
  19. expect(recognized).to have_received(:[])
  20. end
  21. end
  22. context 'with a remote url even if id exists on local' do
  23. let(:status) { Fabricate(:status) }
  24. let(:url) { "https://example.com/users/test/statuses/#{status.id}" }
  25. it 'raises an error' do
  26. expect { subject.status }.to raise_error(ActiveRecord::RecordNotFound)
  27. end
  28. end
  29. context 'with a plausible url' do
  30. let(:url) { 'https://example.com/users/test/updates/123/embed' }
  31. it 'raises an error' do
  32. expect { subject.status }.to raise_error(ActiveRecord::RecordNotFound)
  33. end
  34. end
  35. context 'with an unrecognized url' do
  36. let(:url) { 'https://example.com/about' }
  37. it 'raises an error' do
  38. expect { subject.status }.to raise_error(ActiveRecord::RecordNotFound)
  39. end
  40. end
  41. end
  42. end