0
0
Fork 0

Remove Atom feeds and old URLs in the form of GET /:username/updates/:id (#11247)

This commit is contained in:
Eugen Rochko 2019-07-07 16:16:51 +02:00 committed by GitHub
parent 406b46395d
commit b851456139
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
70 changed files with 130 additions and 2791 deletions

View file

@ -1,63 +0,0 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Streamable do
class Parent
def title; end
def target; end
def thread; end
def self.has_one(*); end
def self.after_create; end
end
class Child < Parent
include Streamable
end
child = Child.new
describe '#title' do
it 'calls Parent#title' do
expect_any_instance_of(Parent).to receive(:title)
child.title
end
end
describe '#content' do
it 'calls #title' do
expect_any_instance_of(Parent).to receive(:title)
child.content
end
end
describe '#target' do
it 'calls Parent#target' do
expect_any_instance_of(Parent).to receive(:target)
child.target
end
end
describe '#object_type' do
it 'returns :activity' do
expect(child.object_type).to eq :activity
end
end
describe '#thread' do
it 'calls Parent#thread' do
expect_any_instance_of(Parent).to receive(:thread)
child.thread
end
end
describe '#hidden?' do
it 'returns false' do
expect(child.hidden?).to be false
end
end
end

View file

@ -1,143 +0,0 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe RemoteProfile do
let(:remote_profile) { RemoteProfile.new(body) }
let(:body) do
<<-XML
<feed xmlns="http://www.w3.org/2005/Atom">
<author>John</author>
XML
end
describe '.initialize' do
it 'calls Nokogiri::XML.parse' do
expect(Nokogiri::XML).to receive(:parse).with(body, nil, 'utf-8')
RemoteProfile.new(body)
end
it 'sets document' do
remote_profile = RemoteProfile.new(body)
expect(remote_profile).not_to be nil
end
end
describe '#root' do
let(:document) { remote_profile.document }
it 'callse document.at_xpath' do
expect(document).to receive(:at_xpath).with(
'/atom:feed|/atom:entry',
atom: OStatus::TagManager::XMLNS
)
remote_profile.root
end
end
describe '#author' do
let(:root) { remote_profile.root }
it 'calls root.at_xpath' do
expect(root).to receive(:at_xpath).with(
'./atom:author|./dfrn:owner',
atom: OStatus::TagManager::XMLNS,
dfrn: OStatus::TagManager::DFRN_XMLNS
)
remote_profile.author
end
end
describe '#hub_link' do
let(:root) { remote_profile.root }
it 'calls #link_href_from_xml' do
expect(remote_profile).to receive(:link_href_from_xml).with(root, 'hub')
remote_profile.hub_link
end
end
describe '#display_name' do
let(:author) { remote_profile.author }
it 'calls author.at_xpath.content' do
expect(author).to receive_message_chain(:at_xpath, :content).with(
'./poco:displayName',
poco: OStatus::TagManager::POCO_XMLNS
).with(no_args)
remote_profile.display_name
end
end
describe '#note' do
let(:author) { remote_profile.author }
it 'calls author.at_xpath.content' do
expect(author).to receive_message_chain(:at_xpath, :content).with(
'./atom:summary|./poco:note',
atom: OStatus::TagManager::XMLNS,
poco: OStatus::TagManager::POCO_XMLNS
).with(no_args)
remote_profile.note
end
end
describe '#scope' do
let(:author) { remote_profile.author }
it 'calls author.at_xpath.content' do
expect(author).to receive_message_chain(:at_xpath, :content).with(
'./mastodon:scope',
mastodon: OStatus::TagManager::MTDN_XMLNS
).with(no_args)
remote_profile.scope
end
end
describe '#avatar' do
let(:author) { remote_profile.author }
it 'calls #link_href_from_xml' do
expect(remote_profile).to receive(:link_href_from_xml).with(author, 'avatar')
remote_profile.avatar
end
end
describe '#header' do
let(:author) { remote_profile.author }
it 'calls #link_href_from_xml' do
expect(remote_profile).to receive(:link_href_from_xml).with(author, 'header')
remote_profile.header
end
end
describe '#locked?' do
before do
allow(remote_profile).to receive(:scope).and_return(scope)
end
subject { remote_profile.locked? }
context 'scope is private' do
let(:scope) { 'private' }
it 'returns true' do
is_expected.to be true
end
end
context 'scope is not private' do
let(:scope) { 'public' }
it 'returns false' do
is_expected.to be false
end
end
end
end

View file

@ -1,192 +0,0 @@
require 'rails_helper'
RSpec.describe StreamEntry, type: :model do
let(:alice) { Fabricate(:account, username: 'alice') }
let(:bob) { Fabricate(:account, username: 'bob') }
let(:status) { Fabricate(:status, account: alice) }
let(:reblog) { Fabricate(:status, account: bob, reblog: status) }
let(:reply) { Fabricate(:status, account: bob, thread: status) }
let(:stream_entry) { Fabricate(:stream_entry, activity: activity) }
let(:activity) { reblog }
describe '#object_type' do
before do
allow(stream_entry).to receive(:orphaned?).and_return(orphaned)
allow(stream_entry).to receive(:targeted?).and_return(targeted)
end
subject { stream_entry.object_type }
context 'orphaned? is true' do
let(:orphaned) { true }
let(:targeted) { false }
it 'returns :activity' do
is_expected.to be :activity
end
end
context 'targeted? is true' do
let(:orphaned) { false }
let(:targeted) { true }
it 'returns :activity' do
is_expected.to be :activity
end
end
context 'orphaned? and targeted? are false' do
let(:orphaned) { false }
let(:targeted) { false }
context 'activity is reblog' do
let(:activity) { reblog }
it 'returns :note' do
is_expected.to be :note
end
end
context 'activity is reply' do
let(:activity) { reply }
it 'returns :comment' do
is_expected.to be :comment
end
end
end
end
describe '#verb' do
before do
allow(stream_entry).to receive(:orphaned?).and_return(orphaned)
end
subject { stream_entry.verb }
context 'orphaned? is true' do
let(:orphaned) { true }
it 'returns :delete' do
is_expected.to be :delete
end
end
context 'orphaned? is false' do
let(:orphaned) { false }
context 'activity is reblog' do
let(:activity) { reblog }
it 'returns :share' do
is_expected.to be :share
end
end
context 'activity is reply' do
let(:activity) { reply }
it 'returns :post' do
is_expected.to be :post
end
end
end
end
describe '#mentions' do
before do
allow(stream_entry).to receive(:orphaned?).and_return(orphaned)
end
subject { stream_entry.mentions }
context 'orphaned? is true' do
let(:orphaned) { true }
it 'returns []' do
is_expected.to eq []
end
end
context 'orphaned? is false' do
before do
reblog.mentions << Fabricate(:mention, account: alice)
reblog.mentions << Fabricate(:mention, account: bob)
end
let(:orphaned) { false }
it 'returns [Account] includes alice and bob' do
is_expected.to eq [alice, bob]
end
end
end
describe '#targeted?' do
it 'returns true for a reblog' do
expect(reblog.stream_entry.targeted?).to be true
end
it 'returns false otherwise' do
expect(status.stream_entry.targeted?).to be false
end
end
describe '#threaded?' do
it 'returns true for a reply' do
expect(reply.stream_entry.threaded?).to be true
end
it 'returns false otherwise' do
expect(status.stream_entry.threaded?).to be false
end
end
describe 'delegated methods' do
context 'with a nil status' do
subject { described_class.new(status: nil) }
it 'returns nil for target' do
expect(subject.target).to be_nil
end
it 'returns nil for title' do
expect(subject.title).to be_nil
end
it 'returns nil for content' do
expect(subject.content).to be_nil
end
it 'returns nil for thread' do
expect(subject.thread).to be_nil
end
end
context 'with a real status' do
let(:original) { Fabricate(:status, text: 'Test status') }
let(:status) { Fabricate(:status, reblog: original, thread: original) }
subject { described_class.new(status: status) }
it 'delegates target' do
expect(status.target).not_to be_nil
expect(subject.target).to eq(status.target)
end
it 'delegates title' do
expect(status.title).not_to be_nil
expect(subject.title).to eq(status.title)
end
it 'delegates content' do
expect(status.content).not_to be_nil
expect(subject.content).to eq(status.content)
end
it 'delegates thread' do
expect(status.thread).not_to be_nil
expect(subject.thread).to eq(status.thread)
end
end
end
end