闭社主体 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.

65 lines
2.0 KiB

  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe StatusFinder do
  4. include RoutingHelper
  5. describe '#status' 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.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 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.status).to eq(stream_entry.status)
  26. end
  27. end
  28. context 'with a remote url even if id exists on local' do
  29. let(:status) { Fabricate(:status) }
  30. let(:url) { "https://example.com/users/test/statuses/#{status.id}" }
  31. subject { described_class.new(url) }
  32. it 'raises an error' do
  33. expect { subject.status }.to raise_error(ActiveRecord::RecordNotFound)
  34. end
  35. end
  36. context 'with a plausible url' do
  37. let(:url) { 'https://example.com/users/test/updates/123/embed' }
  38. subject { described_class.new(url) }
  39. it 'raises an error' do
  40. expect { subject.status }.to raise_error(ActiveRecord::RecordNotFound)
  41. end
  42. end
  43. context 'with an unrecognized url' do
  44. let(:url) { 'https://example.com/about' }
  45. subject { described_class.new(url) }
  46. it 'raises an error' do
  47. expect { subject.status }.to raise_error(ActiveRecord::RecordNotFound)
  48. end
  49. end
  50. end
  51. end