2017-05-31 05:30:06 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
2017-08-30 17:23:43 +09:00
|
|
|
describe StatusFinder do
|
2017-05-31 05:30:06 +09:00
|
|
|
include RoutingHelper
|
|
|
|
|
2017-08-30 17:23:43 +09:00
|
|
|
describe '#status' do
|
2018-06-04 10:35:56 +09:00
|
|
|
subject { described_class.new(url) }
|
|
|
|
|
2017-05-31 05:30:06 +09:00
|
|
|
context 'with a status url' do
|
|
|
|
let(:status) { Fabricate(:status) }
|
|
|
|
let(:url) { short_account_status_url(account_username: status.account.username, id: status.id) }
|
|
|
|
|
|
|
|
it 'finds the stream entry' do
|
2017-08-30 17:23:43 +09:00
|
|
|
expect(subject.status).to eq(status)
|
2017-05-31 05:30:06 +09:00
|
|
|
end
|
2017-06-04 21:56:31 +09:00
|
|
|
|
|
|
|
it 'raises an error if action is not :show' do
|
|
|
|
recognized = Rails.application.routes.recognize_path(url)
|
|
|
|
expect(recognized).to receive(:[]).with(:action).and_return(:create)
|
|
|
|
expect(Rails.application.routes).to receive(:recognize_path).with(url).and_return(recognized)
|
|
|
|
|
2017-08-30 17:23:43 +09:00
|
|
|
expect { subject.status }.to raise_error(ActiveRecord::RecordNotFound)
|
2017-06-04 21:56:31 +09:00
|
|
|
end
|
2017-05-31 05:30:06 +09:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a stream entry url' do
|
|
|
|
let(:stream_entry) { Fabricate(:stream_entry) }
|
|
|
|
let(:url) { account_stream_entry_url(stream_entry.account, stream_entry) }
|
|
|
|
|
|
|
|
it 'finds the stream entry' do
|
2017-08-30 17:23:43 +09:00
|
|
|
expect(subject.status).to eq(stream_entry.status)
|
2017-05-31 05:30:06 +09:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-09-03 00:42:47 +09:00
|
|
|
context 'with a remote url even if id exists on local' do
|
|
|
|
let(:status) { Fabricate(:status) }
|
|
|
|
let(:url) { "https://example.com/users/test/statuses/#{status.id}" }
|
|
|
|
|
|
|
|
it 'raises an error' do
|
|
|
|
expect { subject.status }.to raise_error(ActiveRecord::RecordNotFound)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-31 05:30:06 +09:00
|
|
|
context 'with a plausible url' do
|
|
|
|
let(:url) { 'https://example.com/users/test/updates/123/embed' }
|
|
|
|
|
|
|
|
it 'raises an error' do
|
2017-08-30 17:23:43 +09:00
|
|
|
expect { subject.status }.to raise_error(ActiveRecord::RecordNotFound)
|
2017-05-31 05:30:06 +09:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with an unrecognized url' do
|
|
|
|
let(:url) { 'https://example.com/about' }
|
|
|
|
|
|
|
|
it 'raises an error' do
|
2017-08-30 17:23:43 +09:00
|
|
|
expect { subject.status }.to raise_error(ActiveRecord::RecordNotFound)
|
2017-05-31 05:30:06 +09:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|