闭社主体 forked from https://github.com/tootsuite/mastodon
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.

55 lines
1.7 KiB

  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe StreamEntryFinder do
  4. include RoutingHelper
  5. describe '#stream_entry' do
  6. context 'with a status url' do
  7. let(:status) { Fabricate(:status) }
  8. let(:url) { short_account_status_url(account_username: status.account.username, id: status.id) }
  9. subject { described_class.new(url) }
  10. it 'finds the stream entry' do
  11. expect(subject.stream_entry).to eq(status.stream_entry)
  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.stream_entry }.to raise_error(ActiveRecord::RecordNotFound)
  18. end
  19. end
  20. context 'with a stream entry url' do
  21. let(:stream_entry) { Fabricate(:stream_entry) }
  22. let(:url) { account_stream_entry_url(stream_entry.account, stream_entry) }
  23. subject { described_class.new(url) }
  24. it 'finds the stream entry' do
  25. expect(subject.stream_entry).to eq(stream_entry)
  26. end
  27. end
  28. context 'with a plausible url' do
  29. let(:url) { 'https://example.com/users/test/updates/123/embed' }
  30. subject { described_class.new(url) }
  31. it 'raises an error' do
  32. expect { subject.stream_entry }.to raise_error(ActiveRecord::RecordNotFound)
  33. end
  34. end
  35. context 'with an unrecognized url' do
  36. let(:url) { 'https://example.com/about' }
  37. subject { described_class.new(url) }
  38. it 'raises an error' do
  39. expect { subject.stream_entry }.to raise_error(ActiveRecord::RecordNotFound)
  40. end
  41. end
  42. end
  43. end