diff --git a/app/services/process_feed_service.rb b/app/services/process_feed_service.rb index ff626a0f1..efe40adea 100644 --- a/app/services/process_feed_service.rb +++ b/app/services/process_feed_service.rb @@ -175,7 +175,7 @@ class ProcessFeedService < BaseService end def content(xml) - xml.at_xpath('./xmlns:content').content + xml.at_xpath('./xmlns:content').try(:content) end def thread_id(xml) diff --git a/spec/fixtures/requests/attachment1.txt b/spec/fixtures/requests/attachment1.txt new file mode 100644 index 000000000..77fd9c836 Binary files /dev/null and b/spec/fixtures/requests/attachment1.txt differ diff --git a/spec/fixtures/requests/attachment2.txt b/spec/fixtures/requests/attachment2.txt new file mode 100644 index 000000000..917a1d398 Binary files /dev/null and b/spec/fixtures/requests/attachment2.txt differ diff --git a/spec/fixtures/xml/mastodon.atom b/spec/fixtures/xml/mastodon.atom new file mode 100644 index 000000000..ce28cd77b --- /dev/null +++ b/spec/fixtures/xml/mastodon.atom @@ -0,0 +1,261 @@ + + + http://kickass.zone/users/localhost.atom + ::1 + 2016-10-10T13:29:56Z + http://kickass.zone/system/accounts/avatars/000/000/001/medium/eris.png + + http://activitystrea.ms/schema/1.0/person + http://kickass.zone/users/localhost + localhost + localhost@kickass.zone + + + + + localhost + ::1 + + + + + + + tag:kickass.zone,2016-10-10:objectId=7:objectType=Follow + 2016-10-10T13:29:56Z + 2016-10-10T13:29:56Z + localhost started following kat@mastodon.social + localhost started following kat@mastodon.social + http://activitystrea.ms/schema/1.0/follow + + + http://activitystrea.ms/schema/1.0/activity + + http://activitystrea.ms/schema/1.0/person + https://mastodon.social/users/kat + kat + kat@mastodon.social + #trans #queer + + + + + kat + Kat + #trans #queer + + + + tag:kickass.zone,2016-10-10:objectId=3:objectType=Favourite + 2016-10-10T13:29:26Z + 2016-10-10T13:29:26Z + localhost favourited a status by kat@mastodon.social + localhost favourited a status by kat@mastodon.social + http://activitystrea.ms/schema/1.0/favorite + + + http://activitystrea.ms/schema/1.0/activity + + + http://activitystrea.ms/schema/1.0/comment + tag:mastodon.social,2016-10-10:objectId=22833:objectType=Status + @localhost oooh more mastodons ❤ + + <p><a href="http://kickass.zone/users/localhost">@localhost</a> oooh more mastodons ❤</p> + http://activitystrea.ms/schema/1.0/post + 2016-10-10T13:23:35Z + 2016-10-10T13:23:35Z + + http://activitystrea.ms/schema/1.0/person + https://mastodon.social/users/kat + kat + kat@mastodon.social + #trans #queer + + + + + kat + Kat + #trans #queer + + + + + + tag:kickass.zone,2016-10-10:objectId=2:objectType=Favourite + 2016-10-10T13:13:15Z + 2016-10-10T13:13:15Z + localhost favourited a status by Gargron@mastodon.social + localhost favourited a status by Gargron@mastodon.social + http://activitystrea.ms/schema/1.0/favorite + + + http://activitystrea.ms/schema/1.0/activity + + + http://activitystrea.ms/schema/1.0/note + tag:mastodon.social,2016-10-10:objectId=22825:objectType=Status + Deployed some fixes + + <p>Deployed some fixes</p> + http://activitystrea.ms/schema/1.0/post + 2016-10-10T13:10:37Z + 2016-10-10T13:10:37Z + + http://activitystrea.ms/schema/1.0/person + https://mastodon.social/users/Gargron + Gargron + Gargron@mastodon.social + Developer of Mastodon, a GNU social alternative: https://github.com/Gargron/mastodon + + + + + Gargron + Eugen + Developer of Mastodon, a GNU social alternative: https://github.com/Gargron/mastodon + + + + + tag:kickass.zone,2016-10-10:objectId=17:objectType=Status + 2016-10-10T00:41:31Z + 2016-10-10T00:41:31Z + Social media needs MOAR cats! http://kickass.zone/media/3 + <p>Social media needs MOAR cats! <a rel="nofollow noopener" href="http://kickass.zone/media/3">http://kickass.zone/media/3</a></p> + http://activitystrea.ms/schema/1.0/post + + + http://activitystrea.ms/schema/1.0/note + + + + tag:kickass.zone,2016-10-10:objectId=14:objectType=Status + 2016-10-10T00:38:39Z + 2016-10-10T00:38:39Z + http://kickass.zone/media/2 + <p><a rel="nofollow noopener" href="http://kickass.zone/media/2">http://kickass.zone/media/2</a></p> + http://activitystrea.ms/schema/1.0/post + + + http://activitystrea.ms/schema/1.0/note + + + + tag:kickass.zone,2016-10-10:objectId=12:objectType=Status + 2016-10-10T00:37:49Z + 2016-10-10T00:37:49Z + + <activity:verb>http://activitystrea.ms/schema/1.0/delete</activity:verb> + <link rel="self" type="application/atom+xml" href="http://kickass.zone/users/localhost/updates/7.atom"/> + <link rel="alternate" type="text/html" href="http://kickass.zone/users/localhost/updates/7"/> + <activity:object-type>http://activitystrea.ms/schema/1.0/activity</activity:object-type> + </entry> + <entry> + <id>tag:kickass.zone,2016-10-10:objectId=4:objectType=Follow</id> + <published>2016-10-10T00:23:07Z</published> + <updated>2016-10-10T00:23:07Z</updated> + <title>localhost started following bignimbus@mastodon.social + localhost started following bignimbus@mastodon.social + http://activitystrea.ms/schema/1.0/follow + + + http://activitystrea.ms/schema/1.0/activity + + http://activitystrea.ms/schema/1.0/person + https://mastodon.social/users/bignimbus + bignimbus + bignimbus@mastodon.social + jdauriemma.com + + + + + bignimbus + Jeff Auriemma + jdauriemma.com + + + + tag:kickass.zone,2016-10-10:objectId=2:objectType=Follow + 2016-10-10T00:14:18Z + 2016-10-10T00:14:18Z + localhost started following Gargron@mastodon.social + localhost started following Gargron@mastodon.social + http://activitystrea.ms/schema/1.0/follow + + + http://activitystrea.ms/schema/1.0/activity + + http://activitystrea.ms/schema/1.0/person + https://mastodon.social/users/Gargron + Gargron + Gargron@mastodon.social + Developer of Mastodon, a GNU social alternative: https://github.com/Gargron/mastodon + + + + + Gargron + Eugen + Developer of Mastodon, a GNU social alternative: https://github.com/Gargron/mastodon + + + + tag:kickass.zone,2016-10-10:objectId=1:objectType=Follow + 2016-10-10T00:09:09Z + 2016-10-10T00:09:09Z + localhost started following abc@mastodon.social + localhost started following abc@mastodon.social + http://activitystrea.ms/schema/1.0/follow + + + http://activitystrea.ms/schema/1.0/activity + + http://activitystrea.ms/schema/1.0/person + https://mastodon.social/users/abc + abc + abc@mastodon.social + + + + + abc + abc + + + + tag:kickass.zone,2016-10-10:objectId=3:objectType=Status + 2016-10-10T00:02:47Z + 2016-10-10T00:02:47Z + + <activity:verb>http://activitystrea.ms/schema/1.0/delete</activity:verb> + <link rel="self" type="application/atom+xml" href="http://kickass.zone/users/localhost/updates/3.atom"/> + <link rel="alternate" type="text/html" href="http://kickass.zone/users/localhost/updates/3"/> + <activity:object-type>http://activitystrea.ms/schema/1.0/activity</activity:object-type> + </entry> + <entry> + <id>tag:kickass.zone,2016-10-10:objectId=2:objectType=Status</id> + <published>2016-10-10T00:02:18Z</published> + <updated>2016-10-10T00:02:18Z</updated> + <title>Yes, that was the obligatory first post. :) + <p>Yes, that was the obligatory first post. :)</p> + http://activitystrea.ms/schema/1.0/post + + + http://activitystrea.ms/schema/1.0/comment + + + + tag:kickass.zone,2016-10-10:objectId=1:objectType=Status + 2016-10-10T00:01:56Z + 2016-10-10T00:01:56Z + Hello, world! + <p>Hello, world!</p> + http://activitystrea.ms/schema/1.0/post + + + http://activitystrea.ms/schema/1.0/note + + diff --git a/spec/services/process_feed_service_spec.rb b/spec/services/process_feed_service_spec.rb index 2144c0221..e4e5858ea 100644 --- a/spec/services/process_feed_service_spec.rb +++ b/spec/services/process_feed_service_spec.rb @@ -1,12 +1,50 @@ require 'rails_helper' RSpec.describe ProcessFeedService do + let(:body) { File.read(File.join(Rails.root, 'spec', 'fixtures', 'xml', 'mastodon.atom')) } + let(:account) { Fabricate(:account, username: 'localhost', domain: 'kickass.zone') } + subject { ProcessFeedService.new } - it 'updates remote user\'s account information' - it 'creates posts' - it 'creates reblogs' - it 'creates replies' - it 'creates reblogged replies' - it 'deletes removed posts' + before do + stub_request(:get, "http://kickass.zone/system/accounts/avatars/000/000/001/large/eris.png").to_return(request_fixture('avatar.txt')) + stub_request(:get, "http://kickass.zone/system/media_attachments/files/000/000/002/original/morpheus_linux.jpg?1476059910").to_return(request_fixture('attachment1.txt')) + stub_request(:get, "http://kickass.zone/system/media_attachments/files/000/000/003/original/gizmo.jpg?1476060065").to_return(request_fixture('attachment2.txt')) + + subject.call(body, account) + end + + it 'updates remote user\'s account information' do + expect(account.display_name).to eq '::1' + expect(account).to have_attached_file(:avatar) + end + + it 'creates posts' do + expect(Status.find_by(uri: 'tag:kickass.zone,2016-10-10:objectId=1:objectType=Status')).to_not be_nil + expect(Status.find_by(uri: 'tag:kickass.zone,2016-10-10:objectId=2:objectType=Status')).to_not be_nil + end + + it 'ignores delete statuses unless they existed before' do + expect(Status.find_by(uri: 'tag:kickass.zone,2016-10-10:objectId=3:objectType=Status')).to be_nil + expect(Status.find_by(uri: 'tag:kickass.zone,2016-10-10:objectId=12:objectType=Status')).to be_nil + end + + it 'does not create statuses for follows' do + expect(Status.find_by(uri: 'tag:kickass.zone,2016-10-10:objectId=1:objectType=Follow')).to be_nil + expect(Status.find_by(uri: 'tag:kickass.zone,2016-10-10:objectId=2:objectType=Follow')).to be_nil + expect(Status.find_by(uri: 'tag:kickass.zone,2016-10-10:objectId=4:objectType=Follow')).to be_nil + expect(Status.find_by(uri: 'tag:kickass.zone,2016-10-10:objectId=7:objectType=Follow')).to be_nil + end + + it 'does not create statuses for favourites' do + expect(Status.find_by(uri: 'tag:kickass.zone,2016-10-10:objectId=2:objectType=Favourite')).to be_nil + expect(Status.find_by(uri: 'tag:kickass.zone,2016-10-10:objectId=3:objectType=Favourite')).to be_nil + end + + it 'creates posts with media' do + status = Status.find_by(uri: 'tag:kickass.zone,2016-10-10:objectId=14:objectType=Status') + + expect(status).to_not be_nil + expect(status.media_attachments.first).to have_attached_file(:file) + end end