diff options
author | Ondřej Hruška <ondra@ondrovo.com> | 2017-07-18 18:59:00 +0200 |
---|---|---|
committer | Ondřej Hruška <ondra@ondrovo.com> | 2017-07-18 18:59:00 +0200 |
commit | df74e26baf3c639d0419a7b809208636e81d93f3 (patch) | |
tree | ef0462e5fcc8cc7962ef42d80f7dd520a574a7c5 /spec | |
parent | c727eae4412ac9e4f1bafdc68fe89dcd46d602ca (diff) | |
parent | d69fa9e1f40124279ec9d772e5f54d1e11724e2d (diff) |
Merge branch 'tootsuite-master'
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/admin/reported_statuses_controller_spec.rb | 38 | ||||
-rw-r--r-- | spec/controllers/admin/statuses_controller_spec.rb | 107 | ||||
-rw-r--r-- | spec/lib/ostatus/atom_serializer_spec.rb (renamed from spec/lib/atom_serializer_spec.rb) | 330 | ||||
-rw-r--r-- | spec/lib/user_settings_decorator_spec.rb | 7 | ||||
-rw-r--r-- | spec/models/form/status_batch_spec.rb | 52 | ||||
-rw-r--r-- | spec/models/user_spec.rb | 8 | ||||
-rw-r--r-- | spec/services/process_feed_service_spec.rb | 40 |
7 files changed, 416 insertions, 166 deletions
diff --git a/spec/controllers/admin/reported_statuses_controller_spec.rb b/spec/controllers/admin/reported_statuses_controller_spec.rb index 80c69e8d1..297807d41 100644 --- a/spec/controllers/admin/reported_statuses_controller_spec.rb +++ b/spec/controllers/admin/reported_statuses_controller_spec.rb @@ -11,6 +11,42 @@ describe Admin::ReportedStatusesController do sign_in user, scope: :user end + describe 'POST #create' do + subject do + -> { post :create, params: { report_id: report, form_status_batch: { action: action, status_ids: status_ids } } } + end + + let(:action) { 'nsfw_on' } + let(:status_ids) { [status.id] } + let(:status) { Fabricate(:status, sensitive: !sensitive) } + let(:sensitive) { true } + let!(:media_attachment) { Fabricate(:media_attachment, status: status) } + + context 'updates sensitive column to true' do + it 'updates sensitive column' do + is_expected.to change { + status.reload.sensitive + }.from(false).to(true) + end + end + + context 'updates sensitive column to false' do + let(:action) { 'nsfw_off' } + let(:sensitive) { false } + + it 'updates sensitive column' do + is_expected.to change { + status.reload.sensitive + }.from(true).to(false) + end + end + + it 'redirects to report page' do + subject.call + expect(response).to redirect_to(admin_report_path(report)) + end + end + describe 'PATCH #update' do subject do -> { patch :update, params: { report_id: report, id: status, status: { sensitive: sensitive } } } @@ -48,7 +84,7 @@ describe Admin::ReportedStatusesController do allow(RemovalWorker).to receive(:perform_async) delete :destroy, params: { report_id: report, id: status } - expect(response).to redirect_to(admin_report_path(report)) + expect(response).to have_http_status(:success) expect(RemovalWorker). to have_received(:perform_async).with(status.id) end diff --git a/spec/controllers/admin/statuses_controller_spec.rb b/spec/controllers/admin/statuses_controller_spec.rb new file mode 100644 index 000000000..1515e299b --- /dev/null +++ b/spec/controllers/admin/statuses_controller_spec.rb @@ -0,0 +1,107 @@ +require 'rails_helper' + +describe Admin::StatusesController do + render_views + + let(:user) { Fabricate(:user, admin: true) } + let(:account) { Fabricate(:account) } + let!(:status) { Fabricate(:status, account: account) } + let(:media_attached_status) { Fabricate(:status, account: account, sensitive: !sensitive) } + let!(:media_attachment) { Fabricate(:media_attachment, account: account, status: media_attached_status) } + let(:sensitive) { true } + + before do + sign_in user, scope: :user + end + + describe 'GET #index' do + it 'returns http success with no media' do + get :index, params: { account_id: account.id } + + statuses = assigns(:statuses).to_a + expect(statuses.size).to eq 2 + expect(response).to have_http_status(:success) + end + + it 'returns http success with media' do + get :index, params: { account_id: account.id , media: true } + + statuses = assigns(:statuses).to_a + expect(statuses.size).to eq 1 + expect(response).to have_http_status(:success) + end + end + + describe 'POST #create' do + subject do + -> { post :create, params: { account_id: account.id, form_status_batch: { action: action, status_ids: status_ids } } } + end + + let(:action) { 'nsfw_on' } + let(:status_ids) { [media_attached_status.id] } + + context 'updates sensitive column to true' do + it 'updates sensitive column' do + is_expected.to change { + media_attached_status.reload.sensitive + }.from(false).to(true) + end + end + + context 'updates sensitive column to false' do + let(:action) { 'nsfw_off' } + let(:sensitive) { false } + + it 'updates sensitive column' do + is_expected.to change { + media_attached_status.reload.sensitive + }.from(true).to(false) + end + end + + it 'redirects to account statuses page' do + subject.call + expect(response).to redirect_to(admin_account_statuses_path(account.id)) + end + end + + describe 'PATCH #update' do + subject do + -> { patch :update, params: { account_id: account.id, id: media_attached_status, status: { sensitive: sensitive } } } + end + + context 'updates sensitive column to true' do + it 'updates sensitive column' do + is_expected.to change { + media_attached_status.reload.sensitive + }.from(false).to(true) + end + end + + context 'updates sensitive column to false' do + let(:sensitive) { false } + + it 'updates sensitive column' do + is_expected.to change { + media_attached_status.reload.sensitive + }.from(true).to(false) + end + end + + it 'redirects to account statuses page' do + subject.call + expect(response).to redirect_to(admin_account_statuses_path(account.id)) + end + end + + describe 'DELETE #destroy' do + it 'removes a status' do + allow(RemovalWorker).to receive(:perform_async) + + delete :destroy, params: { account_id: account.id, id: status } + expect(response).to have_http_status(:success) + expect(RemovalWorker). + to have_received(:perform_async).with(status.id) + end + end +end diff --git a/spec/lib/atom_serializer_spec.rb b/spec/lib/ostatus/atom_serializer_spec.rb index d14fc5b40..8caef9355 100644 --- a/spec/lib/atom_serializer_spec.rb +++ b/spec/lib/ostatus/atom_serializer_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe AtomSerializer do +RSpec.describe Ostatus::AtomSerializer do shared_examples 'follow request salmon' do it 'appends author element with account' do account = Fabricate(:account, domain: nil, username: 'username') @@ -108,7 +108,7 @@ RSpec.describe AtomSerializer do it 'returns XML with emojis' do element = Ox::Element.new('tag') element << '💩' - xml = AtomSerializer.render(element) + xml = Ostatus::AtomSerializer.render(element) expect(xml).to eq "<?xml version=\"1.0\"?>\n<tag>💩</tag>\n" end @@ -116,7 +116,7 @@ RSpec.describe AtomSerializer do it 'returns XML, stripping invalid characters like \b and \v' do element = Ox::Element.new('tag') element << "im l33t\b haxo\b\vr" - xml = AtomSerializer.render(element) + xml = Ostatus::AtomSerializer.render(element) expect(xml).to eq "<?xml version=\"1.0\"?>\n<tag>im l33t haxor</tag>\n" end @@ -127,7 +127,7 @@ RSpec.describe AtomSerializer do it 'appends poco:note element with note for local account' do account = Fabricate(:account, domain: nil, note: '<p>note</p>') - author = AtomSerializer.new.author(account) + author = Ostatus::AtomSerializer.new.author(account) note = author.nodes.find { |node| node.name == 'poco:note' } expect(note.text).to eq '<p>note</p>' @@ -136,7 +136,7 @@ RSpec.describe AtomSerializer do it 'appends poco:note element with tags-stripped note for remote account' do account = Fabricate(:account, domain: 'remote', note: '<p>note</p>') - author = AtomSerializer.new.author(account) + author = Ostatus::AtomSerializer.new.author(account) note = author.nodes.find { |node| node.name == 'poco:note' } expect(note.text).to eq 'note' @@ -144,7 +144,7 @@ RSpec.describe AtomSerializer do it 'appends summary element with type attribute and simplified note if present' do account = Fabricate(:account, note: 'note') - author = AtomSerializer.new.author(account) + author = Ostatus::AtomSerializer.new.author(account) expect(author.summary.text).to eq '<p>note</p>' expect(author.summary[:type]).to eq 'html' end @@ -153,27 +153,27 @@ RSpec.describe AtomSerializer do context 'when note is not present' do it 'does not append poco:note element' do account = Fabricate(:account, note: '') - author = AtomSerializer.new.author(account) + author = Ostatus::AtomSerializer.new.author(account) author.nodes.each { |node| expect(node.name).not_to eq 'poco:note' } end it 'does not append summary element' do account = Fabricate(:account, note: '') - author = AtomSerializer.new.author(account) + author = Ostatus::AtomSerializer.new.author(account) author.nodes.each { |node| expect(node.name).not_to eq 'summary' } end end it 'returns author element' do account = Fabricate(:account) - author = AtomSerializer.new.author(account) + author = Ostatus::AtomSerializer.new.author(account) expect(author.name).to eq 'author' end it 'appends activity:object-type element with person type' do account = Fabricate(:account, domain: nil, username: 'username') - author = AtomSerializer.new.author(account) + author = Ostatus::AtomSerializer.new.author(account) object_type = author.nodes.find { |node| node.name == 'activity:object-type' } expect(object_type.text).to eq TagManager::TYPES[:person] @@ -181,20 +181,20 @@ RSpec.describe AtomSerializer do it 'appends email element with username and domain for local account' do account = Fabricate(:account, username: 'username') - author = AtomSerializer.new.author(account) + author = Ostatus::AtomSerializer.new.author(account) expect(author.email.text).to eq 'username@cb6e6126.ngrok.io' end it 'appends email element with username and domain for remote user' do account = Fabricate(:account, domain: 'domain', username: 'username') - author = AtomSerializer.new.author(account) + author = Ostatus::AtomSerializer.new.author(account) expect(author.email.text).to eq 'username@domain' end it 'appends link element for an alternative' do account = Fabricate(:account, domain: nil, username: 'username') - author = AtomSerializer.new.author(account) + author = Ostatus::AtomSerializer.new.author(account) link = author.nodes.find { |node| node.name == 'link' && node[:rel] == 'alternate' } expect(link[:type]).to eq 'text/html' @@ -205,7 +205,7 @@ RSpec.describe AtomSerializer do it 'has link element for avatar if present' do account = Fabricate(:account, avatar: attachment_fixture('avatar.gif')) - author = AtomSerializer.new.author(account) + author = Ostatus::AtomSerializer.new.author(account) link = author.nodes.find { |node| node.name == 'link' && node[:rel] == 'avatar' } expect(link[:type]).to eq 'image/gif' @@ -217,7 +217,7 @@ RSpec.describe AtomSerializer do it 'does not have link element for avatar if not present' do account = Fabricate(:account, avatar: nil) - author = AtomSerializer.new.author(account) + author = Ostatus::AtomSerializer.new.author(account) author.nodes.each do |node| expect(node[:rel]).not_to eq 'avatar' if node.name == 'link' @@ -227,7 +227,7 @@ RSpec.describe AtomSerializer do it 'appends link element for header if present' do account = Fabricate(:account, header: attachment_fixture('avatar.gif')) - author = AtomSerializer.new.author(account) + author = Ostatus::AtomSerializer.new.author(account) link = author.nodes.find { |node| node.name == 'link' && node[:rel] == 'header' } expect(link[:type]).to eq 'image/gif' @@ -239,7 +239,7 @@ RSpec.describe AtomSerializer do it 'does not append link element for header if not present' do account = Fabricate(:account, header: nil) - author = AtomSerializer.new.author(account) + author = Ostatus::AtomSerializer.new.author(account) author.nodes.each do |node| expect(node[:rel]).not_to eq 'header' if node.name == 'link' @@ -249,7 +249,7 @@ RSpec.describe AtomSerializer do it 'appends poco:displayName element with display name if present' do account = Fabricate(:account, display_name: 'display name') - author = AtomSerializer.new.author(account) + author = Ostatus::AtomSerializer.new.author(account) display_name = author.nodes.find { |node| node.name == 'poco:displayName' } expect(display_name.text).to eq 'display name' @@ -257,14 +257,14 @@ RSpec.describe AtomSerializer do it 'does not append poco:displayName element with display name if not present' do account = Fabricate(:account, display_name: '') - author = AtomSerializer.new.author(account) + author = Ostatus::AtomSerializer.new.author(account) author.nodes.each { |node| expect(node.name).not_to eq 'poco:displayName' } end it "appends mastodon:scope element with 'private' if locked" do account = Fabricate(:account, locked: true) - author = AtomSerializer.new.author(account) + author = Ostatus::AtomSerializer.new.author(account) scope = author.nodes.find { |node| node.name == 'mastodon:scope' } expect(scope.text).to eq 'private' @@ -273,7 +273,7 @@ RSpec.describe AtomSerializer do it "appends mastodon:scope element with 'public' if unlocked" do account = Fabricate(:account, locked: false) - author = AtomSerializer.new.author(account) + author = Ostatus::AtomSerializer.new.author(account) scope = author.nodes.find { |node| node.name == 'mastodon:scope' } expect(scope.text).to eq 'public' @@ -282,7 +282,7 @@ RSpec.describe AtomSerializer do it 'includes URI' do account = Fabricate(:account, domain: nil, username: 'username') - author = AtomSerializer.new.author(account) + author = Ostatus::AtomSerializer.new.author(account) expect(author.id.text).to eq 'https://cb6e6126.ngrok.io/users/username' expect(author.uri.text).to eq 'https://cb6e6126.ngrok.io/users/username' @@ -291,7 +291,7 @@ RSpec.describe AtomSerializer do it 'includes username' do account = Fabricate(:account, username: 'username') - author = AtomSerializer.new.author(account) + author = Ostatus::AtomSerializer.new.author(account) name = author.nodes.find { |node| node.name == 'name' } username = author.nodes.find { |node| node.name == 'poco:preferredUsername' } @@ -317,7 +317,7 @@ RSpec.describe AtomSerializer do include_examples 'namespaces' do def serialize stream_entry = Fabricate(:stream_entry) - AtomSerializer.new.entry(stream_entry, true) + Ostatus::AtomSerializer.new.entry(stream_entry, true) end end @@ -325,7 +325,7 @@ RSpec.describe AtomSerializer do account = Fabricate(:account, username: 'username') status = Fabricate(:status, account: account) - entry = AtomSerializer.new.entry(status.stream_entry, true) + entry = Ostatus::AtomSerializer.new.entry(status.stream_entry, true) expect(entry.author.id.text).to eq 'https://cb6e6126.ngrok.io/users/username' end @@ -334,14 +334,14 @@ RSpec.describe AtomSerializer do context 'if status is present' do include_examples 'status attributes' do def serialize(status) - AtomSerializer.new.entry(status.stream_entry, true) + Ostatus::AtomSerializer.new.entry(status.stream_entry, true) end end it 'appends link element for the public collection if status is publicly visible' do status = Fabricate(:status, visibility: :public) - entry = AtomSerializer.new.entry(status.stream_entry) + entry = Ostatus::AtomSerializer.new.entry(status.stream_entry) mentioned_person = entry.nodes.find do |node| node.name == 'link' && @@ -354,7 +354,7 @@ RSpec.describe AtomSerializer do it 'does not append link element for the public collection if status is not publicly visible' do status = Fabricate(:status, visibility: :private) - entry = AtomSerializer.new.entry(status.stream_entry) + entry = Ostatus::AtomSerializer.new.entry(status.stream_entry) entry.nodes.each do |node| if node.name == 'link' && @@ -369,14 +369,14 @@ RSpec.describe AtomSerializer do tag = Fabricate(:tag, name: 'tag') status = Fabricate(:status, tags: [ tag ]) - entry = AtomSerializer.new.entry(status.stream_entry) + entry = Ostatus::AtomSerializer.new.entry(status.stream_entry) expect(entry.category[:term]).to eq 'tag' end it 'appends category element for NSFW if status is sensitive' do status = Fabricate(:status, sensitive: true) - entry = AtomSerializer.new.entry(status.stream_entry) + entry = Ostatus::AtomSerializer.new.entry(status.stream_entry) expect(entry.category[:term]).to eq 'nsfw' end @@ -385,7 +385,7 @@ RSpec.describe AtomSerializer do media_attachment = Fabricate(:media_attachment, file: file) status = Fabricate(:status, media_attachments: [ media_attachment ]) - entry = AtomSerializer.new.entry(status.stream_entry) + entry = Ostatus::AtomSerializer.new.entry(status.stream_entry) enclosure = entry.nodes.find { |node| node.name == 'link' && node[:rel] == 'enclosure' } expect(enclosure[:type]).to eq 'image/jpeg' @@ -395,7 +395,7 @@ RSpec.describe AtomSerializer do it 'appends mastodon:scope element with visibility' do status = Fabricate(:status, visibility: :public) - entry = AtomSerializer.new.entry(status.stream_entry) + entry = Ostatus::AtomSerializer.new.entry(status.stream_entry) scope = entry.nodes.find { |node| node.name == 'mastodon:scope' } expect(scope.text).to eq 'public' @@ -406,8 +406,8 @@ RSpec.describe AtomSerializer do remote_status = Fabricate(:status, account: remote_account) remote_status.stream_entry.update!(created_at: '2000-01-01T00:00:00Z') - entry = AtomSerializer.new.entry(remote_status.stream_entry, true) - xml = AtomSerializer.render(entry).gsub('cb6e6126.ngrok.io', 'remote') + entry = Ostatus::AtomSerializer.new.entry(remote_status.stream_entry, true) + xml = Ostatus::AtomSerializer.render(entry).gsub('cb6e6126.ngrok.io', 'remote') remote_status.destroy! remote_account.destroy! @@ -429,7 +429,7 @@ RSpec.describe AtomSerializer do status = Fabricate(:status) status.destroy! - entry = AtomSerializer.new.entry(status.stream_entry) + entry = Ostatus::AtomSerializer.new.entry(status.stream_entry) expect(entry.content.text).to eq 'Deleted status' end @@ -439,7 +439,7 @@ RSpec.describe AtomSerializer do status = Fabricate(:status, account: account) status.destroy! - entry = AtomSerializer.new.entry(status.stream_entry) + entry = Ostatus::AtomSerializer.new.entry(status.stream_entry) expect(entry.title.text).to eq 'username deleted status' end @@ -447,19 +447,19 @@ RSpec.describe AtomSerializer do context 'it is not root' do let(:stream_entry) { Fabricate(:stream_entry) } - subject { AtomSerializer.new.entry(stream_entry, false) } + subject { Ostatus::AtomSerializer.new.entry(stream_entry, false) } include_examples 'not root' end context 'without root parameter' do let(:stream_entry) { Fabricate(:stream_entry) } - subject { AtomSerializer.new.entry(stream_entry) } + subject { Ostatus::AtomSerializer.new.entry(stream_entry) } include_examples 'not root' end it 'returns entry element' do stream_entry = Fabricate(:stream_entry) - entry = AtomSerializer.new.entry(stream_entry) + entry = Ostatus::AtomSerializer.new.entry(stream_entry) expect(entry.name).to eq 'entry' end @@ -467,33 +467,33 @@ RSpec.describe AtomSerializer do status = Fabricate(:status, reblog_of_id: nil) status.stream_entry.update!(created_at: '2000-01-01T00:00:00Z') - entry = AtomSerializer.new.entry(status.stream_entry) + entry = Ostatus::AtomSerializer.new.entry(status.stream_entry) expect(entry.id.text).to eq "tag:cb6e6126.ngrok.io,2000-01-01:objectId=#{status.id}:objectType=Status" end it 'appends published element with created date' do stream_entry = Fabricate(:stream_entry, created_at: '2000-01-01T00:00:00Z') - entry = AtomSerializer.new.entry(stream_entry) + entry = Ostatus::AtomSerializer.new.entry(stream_entry) expect(entry.published.text).to eq '2000-01-01T00:00:00Z' end it 'appends updated element with updated date' do stream_entry = Fabricate(:stream_entry, updated_at: '2000-01-01T00:00:00Z') - entry = AtomSerializer.new.entry(stream_entry) + entry = Ostatus::AtomSerializer.new.entry(stream_entry) expect(entry.updated.text).to eq '2000-01-01T00:00:00Z' end it 'appends title element with status title' do account = Fabricate(:account, username: 'username') status = Fabricate(:status, account: account, reblog_of_id: nil) - entry = AtomSerializer.new.entry(status.stream_entry) + entry = Ostatus::AtomSerializer.new.entry(status.stream_entry) expect(entry.title.text).to eq 'New status by username' end it 'appends activity:object-type element with object type' do status = Fabricate(:status) - entry = AtomSerializer.new.entry(status.stream_entry) + entry = Ostatus::AtomSerializer.new.entry(status.stream_entry) object_type = entry.nodes.find { |node| node.name == 'activity:object-type' } expect(object_type.text).to eq TagManager::TYPES[:note] end @@ -501,7 +501,7 @@ RSpec.describe AtomSerializer do it 'appends activity:verb element with object type' do status = Fabricate(:status) - entry = AtomSerializer.new.entry(status.stream_entry) + entry = Ostatus::AtomSerializer.new.entry(status.stream_entry) object_type = entry.nodes.find { |node| node.name == 'activity:verb' } expect(object_type.text).to eq TagManager::VERBS[:post] @@ -511,7 +511,7 @@ RSpec.describe AtomSerializer do reblogged = Fabricate(:status, created_at: '2000-01-01T00:00:00Z') reblog = Fabricate(:status, reblog: reblogged) - entry = AtomSerializer.new.entry(reblog.stream_entry) + entry = Ostatus::AtomSerializer.new.entry(reblog.stream_entry) object = entry.nodes.find { |node| node.name == 'activity:object' } expect(object.id.text).to eq "tag:cb6e6126.ngrok.io,2000-01-01:objectId=#{reblogged.id}:objectType=Status" @@ -519,7 +519,7 @@ RSpec.describe AtomSerializer do it 'does not append activity:object element if target is not present' do status = Fabricate(:status, reblog_of_id: nil) - entry = AtomSerializer.new.entry(status.stream_entry) + entry = Ostatus::AtomSerializer.new.entry(status.stream_entry) entry.nodes.each { |node| expect(node.name).not_to eq 'activity:object' } end @@ -527,7 +527,7 @@ RSpec.describe AtomSerializer do account = Fabricate(:account, username: 'username') status = Fabricate(:status, account: account) - entry = AtomSerializer.new.entry(status.stream_entry) + entry = Ostatus::AtomSerializer.new.entry(status.stream_entry) link = entry.nodes.find { |node| node.name == 'link' && node[:rel] == 'alternate' } expect(link[:type]).to eq 'text/html' @@ -538,7 +538,7 @@ RSpec.describe AtomSerializer do account = Fabricate(:account, username: 'username') status = Fabricate(:status, account: account) - entry = AtomSerializer.new.entry(status.stream_entry) + entry = Ostatus::AtomSerializer.new.entry(status.stream_entry) link = entry.nodes.find { |node| node.name == 'link' && node[:rel] == 'self' } expect(link[:type]).to eq 'application/atom+xml' @@ -549,7 +549,7 @@ RSpec.describe AtomSerializer do in_reply_to_status = Fabricate(:status, created_at: '2000-01-01T00:00:00Z', reblog_of_id: nil) reply_status = Fabricate(:status, in_reply_to_id: in_reply_to_status.id) - entry = AtomSerializer.new.entry(reply_status.stream_entry) + entry = Ostatus::AtomSerializer.new.entry(reply_status.stream_entry) in_reply_to = entry.nodes.find { |node| node.name == 'thr:in-reply-to' } expect(in_reply_to[:ref]).to eq "tag:cb6e6126.ngrok.io,2000-01-01:objectId=#{in_reply_to_status.id}:objectType=Status" @@ -557,7 +557,7 @@ RSpec.describe AtomSerializer do it 'does not append thr:in-reply-to element if not threaded' do status = Fabricate(:status) - entry = AtomSerializer.new.entry(status.stream_entry) + entry = Ostatus::AtomSerializer.new.entry(status.stream_entry) entry.nodes.each { |node| expect(node.name).not_to eq 'thr:in-reply-to' } end @@ -565,7 +565,7 @@ RSpec.describe AtomSerializer do status = Fabricate(:status) status.conversation.update!(created_at: '2000-01-01T00:00:00Z') - entry = AtomSerializer.new.entry(status.stream_entry) + entry = Ostatus::AtomSerializer.new.entry(status.stream_entry) conversation = entry.nodes.find { |node| node.name == 'ostatus:conversation' } expect(conversation[:ref]).to eq "tag:cb6e6126.ngrok.io,2000-01-01:objectId=#{status.conversation_id}:objectType=Conversation" @@ -575,7 +575,7 @@ RSpec.describe AtomSerializer do status = Fabricate.build(:status, conversation_id: nil) status.save!(validate: false) - entry = AtomSerializer.new.entry(status.stream_entry) + entry = Ostatus::AtomSerializer.new.entry(status.stream_entry) entry.nodes.each { |node| expect(node.name).not_to eq 'ostatus:conversation' } end @@ -585,62 +585,62 @@ RSpec.describe AtomSerializer do include_examples 'namespaces' do def serialize account = Fabricate(:account) - AtomSerializer.new.feed(account, []) + Ostatus::AtomSerializer.new.feed(account, []) end end it 'returns feed element' do account = Fabricate(:account) - feed = AtomSerializer.new.feed(account, []) + feed = Ostatus::AtomSerializer.new.feed(account, []) expect(feed.name).to eq 'feed' end it 'appends id element with account Atom URL' do account = Fabricate(:account, username: 'username') - feed = AtomSerializer.new.feed(account, []) + feed = Ostatus::AtomSerializer.new.feed(account, []) expect(feed.id.text).to eq 'https://cb6e6126.ngrok.io/users/username.atom' end it 'appends title element with account display name if present' do account = Fabricate(:account, display_name: 'display name') - feed = AtomSerializer.new.feed(account, []) + feed = Ostatus::AtomSerializer.new.feed(account, []) expect(feed.title.text).to eq 'display name' end it 'does not append title element with account username if account display name is not present' do account = Fabricate(:account, display_name: '', username: 'username') - feed = AtomSerializer.new.feed(account, []) + feed = Ostatus::AtomSerializer.new.feed(account, []) expect(feed.title.text).to eq 'username' end it 'appends subtitle element with account note' do account = Fabricate(:account, note: 'note') - feed = AtomSerializer.new.feed(account, []) + feed = Ostatus::AtomSerializer.new.feed(account, []) expect(feed.subtitle.text).to eq 'note' end it 'appends updated element with date account got updated' do account = Fabricate(:account, updated_at: '2000-01-01T00:00:00Z') - feed = AtomSerializer.new.feed(account, []) + feed = Ostatus::AtomSerializer.new.feed(account, []) expect(feed.updated.text).to eq '2000-01-01T00:00:00Z' end it 'appends logo element with full asset URL for original account avatar' do account = Fabricate(:account, avatar: attachment_fixture('avatar.gif')) - feed = AtomSerializer.new.feed(account, []) + feed = Ostatus::AtomSerializer.new.feed(account, []) expect(feed.logo.text).to match /^https:\/\/cb6e6126.ngrok.io\/system\/accounts\/avatars\/.+\/original\/avatar.gif/ end it 'appends author element' do account = Fabricate(:account, username: 'username') - feed = AtomSerializer.new.feed(account, []) + feed = Ostatus::AtomSerializer.new.feed(account, []) expect(feed.author.id.text).to eq 'https://cb6e6126.ngrok.io/users/username' end it 'appends link element for an alternative' do account = Fabricate(:account, username: 'username') - feed = AtomSerializer.new.feed(account, []) + feed = Ostatus::AtomSerializer.new.feed(account, []) link = feed.nodes.find { |node| node.name == 'link' && node[:rel] == 'alternate' } expect(link[:type]).to eq 'text/html' @@ -650,7 +650,7 @@ RSpec.describe AtomSerializer do it 'appends link element for itself' do account = Fabricate(:account, username: 'username') - feed = AtomSerializer.new.feed(account, []) + feed = Ostatus::AtomSerializer.new.feed(account, []) link = feed.nodes.find { |node| node.name == 'link' && node[:rel] == 'self' } expect(link[:type]).to eq 'application/atom+xml' @@ -661,7 +661,7 @@ RSpec.describe AtomSerializer do account = Fabricate(:account, username: 'username') stream_entry = Fabricate(:stream_entry) - feed = AtomSerializer.new.feed(account, Array.new(20, stream_entry)) + feed = Ostatus::AtomSerializer.new.feed(account, Array.new(20, stream_entry)) link = feed.nodes.find { |node| node.name == 'link' && node[:rel] == 'next' } expect(link[:type]).to eq 'application/atom+xml' @@ -671,7 +671,7 @@ RSpec.describe AtomSerializer do it 'does not append link element for the next if it does not have 20 stream entries' do account = Fabricate(:account, username: 'username') - feed = AtomSerializer.new.feed(account, []) + feed = Ostatus::AtomSerializer.new.feed(account, []) feed.nodes.each do |node| expect(node[:rel]).not_to eq 'next' if node.name == 'link' @@ -681,7 +681,7 @@ RSpec.describe AtomSerializer do it 'appends link element for hub' do account = Fabricate(:account, username: 'username') - feed = AtomSerializer.new.feed(account, []) + feed = Ostatus::AtomSerializer.new.feed(account, []) link = feed.nodes.find { |node| node.name == 'link' && node[:rel] == 'hub' } expect(link[:href]).to eq 'https://cb6e6126.ngrok.io/api/push' @@ -690,7 +690,7 @@ RSpec.describe AtomSerializer do it 'appends link element for Salmon' do account = Fabricate(:account, username: 'username') - feed = AtomSerializer.new.feed(account, []) + feed = Ostatus::AtomSerializer.new.feed(account, []) link = feed.nodes.find { |node| node.name == 'link' && node[:rel] == 'salmon' } expect(link[:href]).to start_with 'https://cb6e6126.ngrok.io/api/salmon/' @@ -700,7 +700,7 @@ RSpec.describe AtomSerializer do account = Fabricate(:account, username: 'username') status = Fabricate(:status, account: account) - feed = AtomSerializer.new.feed(account, [status.stream_entry]) + feed = Ostatus::AtomSerializer.new.feed(account, [status.stream_entry]) expect(feed.entry.title.text).to eq 'New status by username' end @@ -710,13 +710,13 @@ RSpec.describe AtomSerializer do include_examples 'namespaces' do def serialize block = Fabricate(:block) - AtomSerializer.new.block_salmon(block) + Ostatus::AtomSerializer.new.block_salmon(block) end end it 'returns entry element' do block = Fabricate(:block) - block_salmon = AtomSerializer.new.block_salmon(block) + block_salmon = Ostatus::AtomSerializer.new.block_salmon(block) expect(block_salmon.name).to eq 'entry' end @@ -724,7 +724,7 @@ RSpec.describe AtomSerializer do block = Fabricate(:block) time_before = Time.now - block_salmon = AtomSerializer.new.block_salmon(block) + block_salmon = Ostatus::AtomSerializer.new.block_salmon(block) time_after = Time.now expect(block_salmon.id.text).to( @@ -738,7 +738,7 @@ RSpec.describe AtomSerializer do target_account = Fabricate(:account, domain: 'remote', username: 'target_account') block = Fabricate(:block, account: account, target_account: target_account) - block_salmon = AtomSerializer.new.block_salmon(block) + block_salmon = Ostatus::AtomSerializer.new.block_salmon(block) expect(block_salmon.title.text).to eq 'account no longer wishes to interact with target_account@remote' end @@ -747,7 +747,7 @@ RSpec.describe AtomSerializer do account = Fabricate(:account, domain: nil, username: 'account') block = Fabricate(:block, account: account) - block_salmon = AtomSerializer.new.block_salmon(block) + block_salmon = Ostatus::AtomSerializer.new.block_salmon(block) expect(block_salmon.author.id.text).to eq 'https://cb6e6126.ngrok.io/users/account' end @@ -755,7 +755,7 @@ RSpec.describe AtomSerializer do it 'appends activity:object-type element with activity type' do block = Fabricate(:block) - block_salmon = AtomSerializer.new.block_salmon(block) + block_salmon = Ostatus::AtomSerializer.new.block_salmon(block) object_type = block_salmon.nodes.find { |node| node.name == 'activity:object-type' } expect(object_type.text).to eq TagManager::TYPES[:activity] @@ -764,7 +764,7 @@ RSpec.describe AtomSerializer do it 'appends activity:verb element with block' do block = Fabricate(:block) - block_salmon = AtomSerializer.new.block_salmon(block) + block_salmon = Ostatus::AtomSerializer.new.block_salmon(block) verb = block_salmon.nodes.find { |node| node.name == 'activity:verb' } expect(verb.text).to eq TagManager::VERBS[:block] @@ -774,7 +774,7 @@ RSpec.describe AtomSerializer do target_account = Fabricate(:account, domain: 'domain', uri: 'https://domain/id') block = Fabricate(:block, target_account: target_account) - block_salmon = AtomSerializer.new.block_salmon(block) + block_salmon = Ostatus::AtomSerializer.new.block_salmon(block) object = block_salmon.nodes.find { |node| node.name == 'activity:object' } expect(object.id.text).to eq 'https://domain/id' @@ -782,8 +782,8 @@ RSpec.describe AtomSerializer do it 'returns element whose rendered view triggers block when processed' do block = Fabricate(:block) - block_salmon = AtomSerializer.new.block_salmon(block) - xml = AtomSerializer.render(block_salmon) + block_salmon = Ostatus::AtomSerializer.new.block_salmon(block) + xml = Ostatus::AtomSerializer.render(block_salmon) envelope = OStatus2::Salmon.new.pack(xml, block.account.keypair) block.destroy! @@ -797,13 +797,13 @@ RSpec.describe AtomSerializer do include_examples 'namespaces' do def serialize block = Fabricate(:block) - AtomSerializer.new.unblock_salmon(block) + Ostatus::AtomSerializer.new.unblock_salmon(block) end end it 'returns entry element' do block = Fabricate(:block) - unblock_salmon = AtomSerializer.new.unblock_salmon(block) + unblock_salmon = Ostatus::AtomSerializer.new.unblock_salmon(block) expect(unblock_salmon.name).to eq 'entry' end @@ -811,7 +811,7 @@ RSpec.describe AtomSerializer do block = Fabricate(:block) time_before = Time.now - unblock_salmon = AtomSerializer.new.unblock_salmon(block) + unblock_salmon = Ostatus::AtomSerializer.new.unblock_salmon(block) time_after = Time.now expect(unblock_salmon.id.text).to( @@ -825,7 +825,7 @@ RSpec.describe AtomSerializer do target_account = Fabricate(:account, domain: 'remote', username: 'target_account') block = Fabricate(:block, account: account, target_account: target_account) - unblock_salmon = AtomSerializer.new.unblock_salmon(block) + unblock_salmon = Ostatus::AtomSerializer.new.unblock_salmon(block) expect(unblock_salmon.title.text).to eq 'account no longer blocks target_account@remote' end @@ -834,7 +834,7 @@ RSpec.describe AtomSerializer do account = Fabricate(:account, domain: nil, username: 'account') block = Fabricate(:block, account: account) - unblock_salmon = AtomSerializer.new.unblock_salmon(block) + unblock_salmon = Ostatus::AtomSerializer.new.unblock_salmon(block) expect(unblock_salmon.author.id.text).to eq 'https://cb6e6126.ngrok.io/users/account' end @@ -842,7 +842,7 @@ RSpec.describe AtomSerializer do it 'appends activity:object-type element with activity type' do block = Fabricate(:block) - unblock_salmon = AtomSerializer.new.unblock_salmon(block) + unblock_salmon = Ostatus::AtomSerializer.new.unblock_salmon(block) object_type = unblock_salmon.nodes.find { |node| node.name == 'activity:object-type' } expect(object_type.text).to eq TagManager::TYPES[:activity] @@ -851,7 +851,7 @@ RSpec.describe AtomSerializer do it 'appends activity:verb element with block' do block = Fabricate(:block) - unblock_salmon = AtomSerializer.new.unblock_salmon(block) + unblock_salmon = Ostatus::AtomSerializer.new.unblock_salmon(block) verb = unblock_salmon.nodes.find { |node| node.name == 'activity:verb' } expect(verb.text).to eq TagManager::VERBS[:unblock] @@ -861,7 +861,7 @@ RSpec.describe AtomSerializer do target_account = Fabricate(:account, domain: 'domain', uri: 'https://domain/id') block = Fabricate(:block, target_account: target_account) - unblock_salmon = AtomSerializer.new.unblock_salmon(block) + unblock_salmon = Ostatus::AtomSerializer.new.unblock_salmon(block) object = unblock_salmon.nodes.find { |node| node.name == 'activity:object' } expect(object.id.text).to eq 'https://domain/id' @@ -869,8 +869,8 @@ RSpec.describe AtomSerializer do it 'returns element whose rendered view triggers block when processed' do block = Fabricate(:block) - unblock_salmon = AtomSerializer.new.unblock_salmon(block) - xml = AtomSerializer.render(unblock_salmon) + unblock_salmon = Ostatus::AtomSerializer.new.unblock_salmon(block) + xml = Ostatus::AtomSerializer.render(unblock_salmon) envelope = OStatus2::Salmon.new.pack(xml, block.account.keypair) ProcessInteractionService.new.call(envelope, block.target_account) @@ -883,19 +883,19 @@ RSpec.describe AtomSerializer do include_examples 'namespaces' do def serialize favourite = Fabricate(:favourite) - AtomSerializer.new.favourite_salmon(favourite) + Ostatus::AtomSerializer.new.favourite_salmon(favourite) end end it 'returns entry element' do favourite = Fabricate(:favourite) - favourite_salmon = AtomSerializer.new.favourite_salmon(favourite) + favourite_salmon = Ostatus::AtomSerializer.new.favourite_salmon(favourite) expect(favourite_salmon.name).to eq 'entry' end it 'appends id element with unique tag' do favourite = Fabricate(:favourite, created_at: '2000-01-01T00:00:00Z') - favourite_salmon = AtomSerializer.new.favourite_salmon(favourite) + favourite_salmon = Ostatus::AtomSerializer.new.favourite_salmon(favourite) expect(favourite_salmon.id.text).to eq "tag:cb6e6126.ngrok.io,2000-01-01:objectId=#{favourite.id}:objectType=Favourite" end @@ -903,7 +903,7 @@ RSpec.describe AtomSerializer do account = Fabricate(:account, domain: nil, username: 'username') favourite = Fabricate(:favourite, account: account) - favourite_salmon = AtomSerializer.new.favourite_salmon(favourite) + favourite_salmon = Ostatus::AtomSerializer.new.favourite_salmon(favourite) expect(favourite_salmon.author.id.text).to eq 'https://cb6e6126.ngrok.io/users/username' end @@ -911,7 +911,7 @@ RSpec.describe AtomSerializer do it 'appends activity:object-type element with activity type' do favourite = Fabricate(:favourite) - favourite_salmon = AtomSerializer.new.favourite_salmon(favourite) + favourite_salmon = Ostatus::AtomSerializer.new.favourite_salmon(favourite) object_type = favourite_salmon.nodes.find { |node| node.name == 'activity:object-type' } expect(object_type.text).to eq 'http://activitystrea.ms/schema/1.0/activity' @@ -920,7 +920,7 @@ RSpec.describe AtomSerializer do it 'appends activity:verb element with favorite' do favourite = Fabricate(:favourite) - favourite_salmon = AtomSerializer.new.favourite_salmon(favourite) + favourite_salmon = Ostatus::AtomSerializer.new.favourite_salmon(favourite) verb = favourite_salmon.nodes.find { |node| node.name == 'activity:verb' } expect(verb.text).to eq TagManager::VERBS[:favorite] @@ -930,7 +930,7 @@ RSpec.describe AtomSerializer do status = Fabricate(:status, created_at: '2000-01-01T00:00:00Z') favourite = Fabricate(:favourite, status: status) - favourite_salmon = AtomSerializer.new.favourite_salmon(favourite) + favourite_salmon = Ostatus::AtomSerializer.new.favourite_salmon(favourite) object = favourite_salmon.nodes.find { |node| node.name == 'activity:object' } expect(object.id.text).to eq "tag:cb6e6126.ngrok.io,2000-01-01:objectId=#{status.id}:objectType=Status" @@ -941,7 +941,7 @@ RSpec.describe AtomSerializer do status = Fabricate(:status, account: status_account, created_at: '2000-01-01T00:00:00Z') favourite = Fabricate(:favourite, status: status) - favourite_salmon = AtomSerializer.new.favourite_salmon(favourite) + favourite_salmon = Ostatus::AtomSerializer.new.favourite_salmon(favourite) in_reply_to = favourite_salmon.nodes.find { |node| node.name == 'thr:in-reply-to' } expect(in_reply_to.ref).to eq "tag:cb6e6126.ngrok.io,2000-01-01:objectId=#{status.id}:objectType=Status" @@ -954,7 +954,7 @@ RSpec.describe AtomSerializer do status = Fabricate(:status, account: status_account) favourite = Fabricate(:favourite, account: account, status: status) - favourite_salmon = AtomSerializer.new.favourite_salmon(favourite) + favourite_salmon = Ostatus::AtomSerializer.new.favourite_salmon(favourite) expect(favourite_salmon.title.text).to eq 'account favourited a status by status_account@remote' expect(favourite_salmon.content.text).to eq 'account favourited a status by status_account@remote' @@ -962,8 +962,8 @@ RSpec.describe AtomSerializer do it 'returns element whose rendered view triggers favourite when processed' do favourite = Fabricate(:favourite) - favourite_salmon = AtomSerializer.new.favourite_salmon(favourite) - xml = AtomSerializer.render(favourite_salmon) + favourite_salmon = Ostatus::AtomSerializer.new.favourite_salmon(favourite) + xml = Ostatus::AtomSerializer.render(favourite_salmon) envelope = OStatus2::Salmon.new.pack(xml, favourite.account.keypair) favourite.destroy! @@ -976,13 +976,13 @@ RSpec.describe AtomSerializer do include_examples 'namespaces' do def serialize favourite = Fabricate(:favourite) - AtomSerializer.new.favourite_salmon(favourite) + Ostatus::AtomSerializer.new.favourite_salmon(favourite) end end it 'returns entry element' do favourite = Fabricate(:favourite) - unfavourite_salmon = AtomSerializer.new.unfavourite_salmon(favourite) + unfavourite_salmon = Ostatus::AtomSerializer.new.unfavourite_salmon(favourite) expect(unfavourite_salmon.name).to eq 'entry' end @@ -990,7 +990,7 @@ RSpec.describe AtomSerializer do favourite = Fabricate(:favourite) time_before = Time.now - unfavourite_salmon = AtomSerializer.new.unfavourite_salmon(favourite) + unfavourite_salmon = Ostatus::AtomSerializer.new.unfavourite_salmon(favourite) time_after = Time.now expect(unfavourite_salmon.id.text).to( @@ -1003,7 +1003,7 @@ RSpec.describe AtomSerializer do account = Fabricate(:account, domain: nil, username: 'username') favourite = Fabricate(:favourite, account: account) - unfavourite_salmon = AtomSerializer.new.unfavourite_salmon(favourite) + unfavourite_salmon = Ostatus::AtomSerializer.new.unfavourite_salmon(favourite) expect(unfavourite_salmon.author.id.text).to eq 'https://cb6e6126.ngrok.io/users/username' end @@ -1011,7 +1011,7 @@ RSpec.describe AtomSerializer do it 'appends activity:object-type element with activity type' do favourite = Fabricate(:favourite) - unfavourite_salmon = AtomSerializer.new.unfavourite_salmon(favourite) + unfavourite_salmon = Ostatus::AtomSerializer.new.unfavourite_salmon(favourite) object_type = unfavourite_salmon.nodes.find { |node| node.name == 'activity:object-type' } expect(object_type.text).to eq 'http://activitystrea.ms/schema/1.0/activity' @@ -1020,7 +1020,7 @@ RSpec.describe AtomSerializer do it 'appends activity:verb element with favorite' do favourite = Fabricate(:favourite) - unfavourite_salmon = AtomSerializer.new.unfavourite_salmon(favourite) + unfavourite_salmon = Ostatus::AtomSerializer.new.unfavourite_salmon(favourite) verb = unfavourite_salmon.nodes.find { |node| node.name == 'activity:verb' } expect(verb.text).to eq TagManager::VERBS[:unfavorite] @@ -1030,7 +1030,7 @@ RSpec.describe AtomSerializer do status = Fabricate(:status, created_at: '2000-01-01T00:00:00Z') favourite = Fabricate(:favourite, status: status) - unfavourite_salmon = AtomSerializer.new.unfavourite_salmon(favourite) + unfavourite_salmon = Ostatus::AtomSerializer.new.unfavourite_salmon(favourite) object = unfavourite_salmon.nodes.find { |node| node.name == 'activity:object' } expect(object.id.text).to eq "tag:cb6e6126.ngrok.io,2000-01-01:objectId=#{status.id}:objectType=Status" @@ -1041,7 +1041,7 @@ RSpec.describe AtomSerializer do status = Fabricate(:status, account: status_account, created_at: '2000-01-01T00:00:00Z') favourite = Fabricate(:favourite, status: status) - unfavourite_salmon = AtomSerializer.new.unfavourite_salmon(favourite) + unfavourite_salmon = Ostatus::AtomSerializer.new.unfavourite_salmon(favourite) in_reply_to = unfavourite_salmon.nodes.find { |node| node.name == 'thr:in-reply-to' } expect(in_reply_to.ref).to eq "tag:cb6e6126.ngrok.io,2000-01-01:objectId=#{status.id}:objectType=Status" @@ -1054,7 +1054,7 @@ RSpec.describe AtomSerializer do status = Fabricate(:status, account: status_account) favourite = Fabricate(:favourite, account: account, status: status) - unfavourite_salmon = AtomSerializer.new.unfavourite_salmon(favourite) + unfavourite_salmon = Ostatus::AtomSerializer.new.unfavourite_salmon(favourite) expect(unfavourite_salmon.title.text).to eq 'account no longer favourites a status by status_account@remote' expect(unfavourite_salmon.content.text).to eq 'account no longer favourites a status by status_account@remote' @@ -1062,8 +1062,8 @@ RSpec.describe AtomSerializer do it 'returns element whose rendered view triggers unfavourite when processed' do favourite = Fabricate(:favourite) - unfavourite_salmon = AtomSerializer.new.unfavourite_salmon(favourite) - xml = AtomSerializer.render(unfavourite_salmon) + unfavourite_salmon = Ostatus::AtomSerializer.new.unfavourite_salmon(favourite) + xml = Ostatus::AtomSerializer.render(unfavourite_salmon) envelope = OStatus2::Salmon.new.pack(xml, favourite.account.keypair) ProcessInteractionService.new.call(envelope, favourite.status.account) @@ -1075,19 +1075,19 @@ RSpec.describe AtomSerializer do include_examples 'namespaces' do def serialize follow = Fabricate(:follow) - AtomSerializer.new.follow_salmon(follow) + Ostatus::AtomSerializer.new.follow_salmon(follow) end end it 'returns entry element' do follow = Fabricate(:follow) - follow_salmon = AtomSerializer.new.follow_salmon(follow) + follow_salmon = Ostatus::AtomSerializer.new.follow_salmon(follow) expect(follow_salmon.name).to eq 'entry' end it 'appends id element with unique tag' do follow = Fabricate(:follow, created_at: '2000-01-01T00:00:00Z') - follow_salmon = AtomSerializer.new.follow_salmon(follow) + follow_salmon = Ostatus::AtomSerializer.new.follow_salmon(follow) expect(follow_salmon.id.text).to eq "tag:cb6e6126.ngrok.io,2000-01-01:objectId=#{follow.id}:objectType=Follow" end @@ -1095,7 +1095,7 @@ RSpec.describe AtomSerializer do account = Fabricate(:account, domain: nil, username: 'username') follow = Fabricate(:follow, account: account) - follow_salmon = AtomSerializer.new.follow_salmon(follow) + follow_salmon = Ostatus::AtomSerializer.new.follow_salmon(follow) expect(follow_salmon.author.id.text).to eq 'https://cb6e6126.ngrok.io/users/username' end @@ -1103,7 +1103,7 @@ RSpec.describe AtomSerializer do it 'appends activity:object-type element with activity type' do follow = Fabricate(:follow) - follow_salmon = AtomSerializer.new.follow_salmon(follow) + follow_salmon = Ostatus::AtomSerializer.new.follow_salmon(follow) object_type = follow_salmon.nodes.find { |node| node.name == 'activity:object-type' } expect(object_type.text).to eq TagManager::TYPES[:activity] @@ -1112,7 +1112,7 @@ RSpec.describe AtomSerializer do it 'appends activity:verb element with follow' do follow = Fabricate(:follow) - follow_salmon = AtomSerializer.new.follow_salmon(follow) + follow_salmon = Ostatus::AtomSerializer.new.follow_salmon(follow) verb = follow_salmon.nodes.find { |node| node.name == 'activity:verb' } expect(verb.text).to eq TagManager::VERBS[:follow] @@ -1122,7 +1122,7 @@ RSpec.describe AtomSerializer do target_account = Fabricate(:account, domain: 'domain', uri: 'https://domain/id') follow = Fabricate(:follow, target_account: target_account) - follow_salmon = AtomSerializer.new.follow_salmon(follow) + follow_salmon = Ostatus::AtomSerializer.new.follow_salmon(follow) object = follow_salmon.nodes.find { |node| node.name == 'activity:object' } expect(object.id.text).to eq 'https://domain/id' @@ -1133,7 +1133,7 @@ RSpec.describe AtomSerializer do target_account = Fabricate(:account, domain: 'remote', username: 'target_account') follow = Fabricate(:follow, account: account, target_account: target_account) - follow_salmon = AtomSerializer.new.follow_salmon(follow) + follow_salmon = Ostatus::AtomSerializer.new.follow_salmon(follow) expect(follow_salmon.title.text).to eq 'account started following target_account@remote' expect(follow_salmon.content.text).to eq 'account started following target_account@remote' @@ -1141,8 +1141,8 @@ RSpec.describe AtomSerializer do it 'returns element whose rendered view triggers follow when processed' do follow = Fabricate(:follow) - follow_salmon = AtomSerializer.new.follow_salmon(follow) - xml = AtomSerializer.render(follow_salmon) + follow_salmon = Ostatus::AtomSerializer.new.follow_salmon(follow) + xml = Ostatus::AtomSerializer.render(follow_salmon) follow.destroy! envelope = OStatus2::Salmon.new.pack(xml, follow.account.keypair) @@ -1157,7 +1157,7 @@ RSpec.describe AtomSerializer do def serialize follow = Fabricate(:follow) follow.destroy! - AtomSerializer.new.unfollow_salmon(follow) + Ostatus::AtomSerializer.new.unfollow_salmon(follow) end end @@ -1165,7 +1165,7 @@ RSpec.describe AtomSerializer do follow = Fabricate(:follow) follow.destroy! - unfollow_salmon = AtomSerializer.new.unfollow_salmon(follow) + unfollow_salmon = Ostatus::AtomSerializer.new.unfollow_salmon(follow) expect(unfollow_salmon.name).to eq 'entry' end @@ -1175,7 +1175,7 @@ RSpec.describe AtomSerializer do follow.destroy! time_before = Time.now - unfollow_salmon = AtomSerializer.new.unfollow_salmon(follow) + unfollow_salmon = Ostatus::AtomSerializer.new.unfollow_salmon(follow) time_after = Time.now expect(unfollow_salmon.id.text).to( @@ -1190,7 +1190,7 @@ RSpec.describe AtomSerializer do follow = Fabricate(:follow, account: account, target_account: target_account) follow.destroy! - unfollow_salmon = AtomSerializer.new.unfollow_salmon(follow) + unfollow_salmon = Ostatus::AtomSerializer.new.unfollow_salmon(follow) expect(unfollow_salmon.title.text).to eq 'account is no longer following target_account@remote' end @@ -1201,7 +1201,7 @@ RSpec.describe AtomSerializer do follow = Fabricate(:follow, account: account, target_account: target_account) follow.destroy! - unfollow_salmon = AtomSerializer.new.unfollow_salmon(follow) + unfollow_salmon = Ostatus::AtomSerializer.new.unfollow_salmon(follow) expect(unfollow_salmon.content.text).to eq 'account is no longer following target_account@remote' end @@ -1211,7 +1211,7 @@ RSpec.describe AtomSerializer do follow = Fabricate(:follow, account: account) follow.destroy! - unfollow_salmon = AtomSerializer.new.unfollow_salmon(follow) + unfollow_salmon = Ostatus::AtomSerializer.new.unfollow_salmon(follow) expect(unfollow_salmon.author.id.text).to eq 'https://cb6e6126.ngrok.io/users/username' end @@ -1220,7 +1220,7 @@ RSpec.describe AtomSerializer do follow = Fabricate(:follow) follow.destroy! - unfollow_salmon = AtomSerializer.new.unfollow_salmon(follow) + unfollow_salmon = Ostatus::AtomSerializer.new.unfollow_salmon(follow) object_type = unfollow_salmon.nodes.find { |node| node.name == 'activity:object-type' } expect(object_type.text).to eq TagManager::TYPES[:activity] @@ -1230,7 +1230,7 @@ RSpec.describe AtomSerializer do follow = Fabricate(:follow) follow.destroy! - unfollow_salmon = AtomSerializer.new.unfollow_salmon(follow) + unfollow_salmon = Ostatus::AtomSerializer.new.unfollow_salmon(follow) verb = unfollow_salmon.nodes.find { |node| node.name == 'activity:verb' } expect(verb.text).to eq TagManager::VERBS[:unfollow] @@ -1241,7 +1241,7 @@ RSpec.describe AtomSerializer do follow = Fabricate(:follow, target_account: target_account) follow.destroy! - unfollow_salmon = AtomSerializer.new.unfollow_salmon(follow) + unfollow_salmon = Ostatus::AtomSerializer.new.unfollow_salmon(follow) object = unfollow_salmon.nodes.find { |node| node.name == 'activity:object' } expect(object.id.text).to eq 'https://domain/id' @@ -1250,8 +1250,8 @@ RSpec.describe AtomSerializer do it 'returns element whose rendered view triggers unfollow when processed' do follow = Fabricate(:follow) follow.destroy! - unfollow_salmon = AtomSerializer.new.unfollow_salmon(follow) - xml = AtomSerializer.render(unfollow_salmon) + unfollow_salmon = Ostatus::AtomSerializer.new.unfollow_salmon(follow) + xml = Ostatus::AtomSerializer.render(unfollow_salmon) follow.account.follow!(follow.target_account) envelope = OStatus2::Salmon.new.pack(xml, follow.account.keypair) @@ -1265,13 +1265,13 @@ RSpec.describe AtomSerializer do include_examples 'namespaces' do def serialize follow_request = Fabricate(:follow_request) - AtomSerializer.new.follow_request_salmon(follow_request) + Ostatus::AtomSerializer.new.follow_request_salmon(follow_request) end end context do def serialize(follow_request) - AtomSerializer.new.follow_request_salmon(follow_request) + Ostatus::AtomSerializer.new.follow_request_salmon(follow_request) end it_behaves_like 'follow request salmon' @@ -1293,7 +1293,7 @@ RSpec.describe AtomSerializer do it 'returns element whose rendered view triggers follow request when processed' do follow_request = Fabricate(:follow_request) follow_request_salmon = serialize(follow_request) - xml = AtomSerializer.render(follow_request_salmon) + xml = Ostatus::AtomSerializer.render(follow_request_salmon) envelope = OStatus2::Salmon.new.pack(xml, follow_request.account.keypair) follow_request.destroy! @@ -1308,13 +1308,13 @@ RSpec.describe AtomSerializer do include_examples 'namespaces' do def serialize follow_request = Fabricate(:follow_request) - AtomSerializer.new.authorize_follow_request_salmon(follow_request) + Ostatus::AtomSerializer.new.authorize_follow_request_salmon(follow_request) end end it_behaves_like 'follow request salmon' do def serialize(follow_request) - authorize_follow_request_salmon = AtomSerializer.new.authorize_follow_request_salmon(follow_request) + authorize_follow_request_salmon = Ostatus::AtomSerializer.new.authorize_follow_request_salmon(follow_request) authorize_follow_request_salmon.nodes.find { |node| node.name == 'activity:object' } end end @@ -1323,7 +1323,7 @@ RSpec.describe AtomSerializer do follow_request = Fabricate(:follow_request) time_before = Time.now - authorize_follow_request_salmon = AtomSerializer.new.authorize_follow_request_salmon(follow_request) + authorize_follow_request_salmon = Ostatus::AtomSerializer.new.authorize_follow_request_salmon(follow_request) time_after = Time.now expect(authorize_follow_request_salmon.id.text).to( @@ -1337,7 +1337,7 @@ RSpec.describe AtomSerializer do target_account = Fabricate(:account, domain: nil, username: 'target_account') follow_request = Fabricate(:follow_request, account: account, target_account: target_account) - authorize_follow_request_salmon = AtomSerializer.new.authorize_follow_request_salmon(follow_request) + authorize_follow_request_salmon = Ostatus::AtomSerializer.new.authorize_follow_request_salmon(follow_request) expect(authorize_follow_request_salmon.title.text).to eq 'target_account authorizes follow request by account@remote' end @@ -1345,7 +1345,7 @@ RSpec.describe AtomSerializer do it 'appends activity:object-type element with activity type' do follow_request = Fabricate(:follow_request) - authorize_follow_request_salmon = AtomSerializer.new.authorize_follow_request_salmon(follow_request) + authorize_follow_request_salmon = Ostatus::AtomSerializer.new.authorize_follow_request_salmon(follow_request) object_type = authorize_follow_request_salmon.nodes.find { |node| node.name == 'activity:object-type' } expect(object_type.text).to eq TagManager::TYPES[:activity] @@ -1354,7 +1354,7 @@ RSpec.describe AtomSerializer do it 'appends activity:verb element with authorize' do follow_request = Fabricate(:follow_request) - authorize_follow_request_salmon = AtomSerializer.new.authorize_follow_request_salmon(follow_request) + authorize_follow_request_salmon = Ostatus::AtomSerializer.new.authorize_follow_request_salmon(follow_request) verb = authorize_follow_request_salmon.nodes.find { |node| node.name == 'activity:verb' } expect(verb.text).to eq TagManager::VERBS[:authorize] @@ -1362,8 +1362,8 @@ RSpec.describe AtomSerializer do it 'returns element whose rendered view creates follow from follow request when processed' do follow_request = Fabricate(:follow_request) - authorize_follow_request_salmon = AtomSerializer.new.authorize_follow_request_salmon(follow_request) - xml = AtomSerializer.render(authorize_follow_request_salmon) + authorize_follow_request_salmon = Ostatus::AtomSerializer.new.authorize_follow_request_salmon(follow_request) + xml = Ostatus::AtomSerializer.render(authorize_follow_request_salmon) envelope = OStatus2::Salmon.new.pack(xml, follow_request.target_account.keypair) ProcessInteractionService.new.call(envelope, follow_request.account) @@ -1377,13 +1377,13 @@ RSpec.describe AtomSerializer do include_examples 'namespaces' do def serialize follow_request = Fabricate(:follow_request) - AtomSerializer.new.reject_follow_request_salmon(follow_request) + Ostatus::AtomSerializer.new.reject_follow_request_salmon(follow_request) end end it_behaves_like 'follow request salmon' do def serialize(follow_request) - reject_follow_request_salmon = AtomSerializer.new.reject_follow_request_salmon(follow_request) + reject_follow_request_salmon = Ostatus::AtomSerializer.new.reject_follow_request_salmon(follow_request) reject_follow_request_salmon.nodes.find { |node| node.name == 'activity:object' } end end @@ -1392,7 +1392,7 @@ RSpec.describe AtomSerializer do follow_request = Fabricate(:follow_request) time_before = Time.now - reject_follow_request_salmon = AtomSerializer.new.reject_follow_request_salmon(follow_request) + reject_follow_request_salmon = Ostatus::AtomSerializer.new.reject_follow_request_salmon(follow_request) time_after = Time.now expect(reject_follow_request_salmon.id.text).to( @@ -1405,28 +1405,28 @@ RSpec.describe AtomSerializer do account = Fabricate(:account, domain: 'remote', username: 'account') target_account = Fabricate(:account, domain: nil, username: 'target_account') follow_request = Fabricate(:follow_request, account: account, target_account: target_account) - reject_follow_request_salmon = AtomSerializer.new.reject_follow_request_salmon(follow_request) + reject_follow_request_salmon = Ostatus::AtomSerializer.new.reject_follow_request_salmon(follow_request) expect(reject_follow_request_salmon.title.text).to eq 'target_account rejects follow request by account@remote' end it 'appends activity:object-type element with activity type' do follow_request = Fabricate(:follow_request) - reject_follow_request_salmon = AtomSerializer.new.reject_follow_request_salmon(follow_request) + reject_follow_request_salmon = Ostatus::AtomSerializer.new.reject_follow_request_salmon(follow_request) object_type = reject_follow_request_salmon.nodes.find { |node| node.name == 'activity:object-type' } expect(object_type.text).to eq TagManager::TYPES[:activity] end it 'appends activity:verb element with authorize' do follow_request = Fabricate(:follow_request) - reject_follow_request_salmon = AtomSerializer.new.reject_follow_request_salmon(follow_request) + reject_follow_request_salmon = Ostatus::AtomSerializer.new.reject_follow_request_salmon(follow_request) verb = reject_follow_request_salmon.nodes.find { |node| node.name == 'activity:verb' } expect(verb.text).to eq TagManager::VERBS[:reject] end it 'returns element whose rendered view deletes follow request when processed' do follow_request = Fabricate(:follow_request) - reject_follow_request_salmon = AtomSerializer.new.reject_follow_request_salmon(follow_request) - xml = AtomSerializer.render(reject_follow_request_salmon) + reject_follow_request_salmon = Ostatus::AtomSerializer.new.reject_follow_request_salmon(follow_request) + xml = Ostatus::AtomSerializer.render(reject_follow_request_salmon) envelope = OStatus2::Salmon.new.pack(xml, follow_request.target_account.keypair) ProcessInteractionService.new.call(envelope, follow_request.account) @@ -1439,31 +1439,31 @@ RSpec.describe AtomSerializer do describe '#object' do include_examples 'status attributes' do def serialize(status) - AtomSerializer.new.object(status) + Ostatus::AtomSerializer.new.object(status) end end it 'returns activity:object element' do status = Fabricate(:status) - object = AtomSerializer.new.object(status) + object = Ostatus::AtomSerializer.new.object(status) expect(object.name).to eq 'activity:object' end it 'appends id element with URL for status' do status = Fabricate(:status, created_at: '2000-01-01T00:00:00Z') - object = AtomSerializer.new.object(status) + object = Ostatus::AtomSerializer.new.object(status) expect(object.id.text).to eq "tag:cb6e6126.ngrok.io,2000-01-01:objectId=#{status.id}:objectType=Status" end it 'appends published element with created date' do status = Fabricate(:status, created_at: '2000-01-01T00:00:00Z') - object = AtomSerializer.new.object(status) + object = Ostatus::AtomSerializer.new.object(status) expect(object.published.text).to eq '2000-01-01T00:00:00Z' end it 'appends updated element with updated date' do status = Fabricate(:status, updated_at: '2000-01-01T00:00:00Z') - object = AtomSerializer.new.object(status) + object = Ostatus::AtomSerializer.new.object(status) expect(object.updated.text).to eq '2000-01-01T00:00:00Z' end @@ -1471,7 +1471,7 @@ RSpec.describe AtomSerializer do account = Fabricate(:account, username: 'username') status = Fabricate(:status, account: account) - object = AtomSerializer.new.object(status) + object = Ostatus::AtomSerializer.new.object(status) expect(object.title.text).to eq 'New status by username' end @@ -1480,7 +1480,7 @@ RSpec.describe AtomSerializer do account = Fabricate(:account, username: 'username') status = Fabricate(:status, account: account) - entry = AtomSerializer.new.object(status) + entry = Ostatus::AtomSerializer.new.object(status) expect(entry.author.id.text).to eq 'https://cb6e6126.ngrok.io/users/username' end @@ -1488,7 +1488,7 @@ RSpec.describe AtomSerializer do it 'appends activity:object-type element with object type' do status = Fabricate(:status) - entry = AtomSerializer.new.object(status) + entry = Ostatus::AtomSerializer.new.object(status) object_type = entry.nodes.find { |node| node.name == 'activity:object-type' } expect(object_type.text).to eq TagManager::TYPES[:note] @@ -1497,7 +1497,7 @@ RSpec.describe AtomSerializer do it 'appends activity:verb element with verb' do status = Fabricate(:status) - entry = AtomSerializer.new.object(status) + entry = Ostatus::AtomSerializer.new.object(status) object_type = entry.nodes.find { |node| node.name == 'activity:verb' } expect(object_type.text).to eq TagManager::VERBS[:post] @@ -1507,7 +1507,7 @@ RSpec.describe AtomSerializer do account = Fabricate(:account, username: 'username') status = Fabricate(:status, account: account) - entry = AtomSerializer.new.object(status) + entry = Ostatus::AtomSerializer.new.object(status) link = entry.nodes.find { |node| node.name == 'link' && node[:rel] == 'alternate' } expect(link[:type]).to eq 'text/html' @@ -1519,7 +1519,7 @@ RSpec.describe AtomSerializer do thread = Fabricate(:status, account: account, created_at: '2000-01-01T00:00:00Z') reply = Fabricate(:status, thread: thread) - entry = AtomSerializer.new.object(reply) + entry = Ostatus::AtomSerializer.new.object(reply) in_reply_to = entry.nodes.find { |node| node.name == 'thr:in-reply-to' } expect(in_reply_to.ref).to eq "tag:cb6e6126.ngrok.io,2000-01-01:objectId=#{thread.id}:objectType=Status" @@ -1528,7 +1528,7 @@ RSpec.describe AtomSerializer do it 'does not append thr:in-reply-to element if thread is nil' do status = Fabricate(:status, thread: nil) - entry = AtomSerializer.new.object(status) + entry = Ostatus::AtomSerializer.new.object(status) entry.nodes.each { |node| expect(node.name).not_to eq 'thr:in-reply-to' } end @@ -1536,7 +1536,7 @@ RSpec.describe AtomSerializer do status = Fabricate.build(:status, conversation_id: nil) status.save!(validate: false) - entry = AtomSerializer.new.object(status) + entry = Ostatus::AtomSerializer.new.object(status) entry.nodes.each { |node| expect(node.name).not_to eq 'ostatus:conversation' } end @@ -1545,7 +1545,7 @@ RSpec.describe AtomSerializer do status = Fabricate(:status) status.conversation.update!(created_at: '2000-01-01T00:00:00Z') - entry = AtomSerializer.new.object(status) + entry = Ostatus::AtomSerializer.new.object(status) conversation = entry.nodes.find { |node| node.name == 'ostatus:conversation' } expect(conversation[:ref]).to eq "tag:cb6e6126.ngrok.io,2000-01-01:objectId=#{status.conversation.id}:objectType=Conversation" diff --git a/spec/lib/user_settings_decorator_spec.rb b/spec/lib/user_settings_decorator_spec.rb index a67487779..6fbf6536b 100644 --- a/spec/lib/user_settings_decorator_spec.rb +++ b/spec/lib/user_settings_decorator_spec.rb @@ -35,6 +35,13 @@ describe UserSettingsDecorator do expect(user.settings['default_sensitive']).to eq true end + it 'updates the user settings value for unfollow modal' do + values = { 'setting_unfollow_modal' => '0' } + + settings.update(values) + expect(user.settings['unfollow_modal']).to eq false + end + it 'updates the user settings value for boost modal' do values = { 'setting_boost_modal' => '1' } diff --git a/spec/models/form/status_batch_spec.rb b/spec/models/form/status_batch_spec.rb new file mode 100644 index 000000000..00c790a11 --- /dev/null +++ b/spec/models/form/status_batch_spec.rb @@ -0,0 +1,52 @@ +require 'rails_helper' + +describe Form::StatusBatch do + let(:form) { Form::StatusBatch.new(action: action, status_ids: status_ids) } + let(:status) { Fabricate(:status) } + + describe 'with nsfw action' do + let(:status_ids) { [status.id, nonsensitive_status.id, sensitive_status.id] } + let(:nonsensitive_status) { Fabricate(:status, sensitive: false) } + let(:sensitive_status) { Fabricate(:status, sensitive: true) } + let!(:shown_media_attachment) { Fabricate(:media_attachment, status: nonsensitive_status) } + let!(:hidden_media_attachment) { Fabricate(:media_attachment, status: sensitive_status) } + + context 'nsfw_on' do + let(:action) { 'nsfw_on' } + + it { expect(form.save).to be true } + it { expect { form.save }.to change { nonsensitive_status.reload.sensitive }.from(false).to(true) } + it { expect { form.save }.not_to change { sensitive_status.reload.sensitive } } + it { expect { form.save }.not_to change { status.reload.sensitive } } + end + + context 'nsfw_off' do + let(:action) { 'nsfw_off' } + + it { expect(form.save).to be true } + it { expect { form.save }.to change { sensitive_status.reload.sensitive }.from(true).to(false) } + it { expect { form.save }.not_to change { nonsensitive_status.reload.sensitive } } + it { expect { form.save }.not_to change { status.reload.sensitive } } + end + end + + describe 'with delete action' do + let(:status_ids) { [status.id] } + let(:action) { 'delete' } + let!(:another_status) { Fabricate(:status) } + + before do + allow(RemovalWorker).to receive(:perform_async) + end + + it 'call RemovalWorker' do + form.save + expect(RemovalWorker).to have_received(:perform_async).with(status.id) + end + + it 'do not call RemovalWorker' do + form.save + expect(RemovalWorker).not_to have_received(:perform_async).with(another_status.id) + end + end +end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 2019ec0f6..ef45818b9 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -219,6 +219,14 @@ RSpec.describe User, type: :model do end end + describe '#setting_unfollow_modal' do + it 'returns unfollow modal setting' do + user = Fabricate(:user) + user.settings[:unfollow_modal] = true + expect(user.setting_unfollow_modal).to eq true + end + end + describe '#setting_delete_modal' do it 'returns delete modal setting' do user = Fabricate(:user) diff --git a/spec/services/process_feed_service_spec.rb b/spec/services/process_feed_service_spec.rb index d85ee3b56..5e34370ee 100644 --- a/spec/services/process_feed_service_spec.rb +++ b/spec/services/process_feed_service_spec.rb @@ -167,6 +167,46 @@ XML expect(created_statuses.first.reblog.text).to eq 'Overwatch rocks' end + it 'ignores reblogs if it failed to retreive reblogged statuses' do + stub_request(:head, 'https://overwatch.com/users/tracer/updates/1').to_return(status: 404) + + actor = Fabricate(:account, username: 'tracer', domain: 'overwatch.com') + + body = <<XML +<?xml version="1.0"?> +<entry xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:activity="http://activitystrea.ms/spec/1.0/" xmlns:poco="http://portablecontacts.net/spec/1.0" xmlns:media="http://purl.org/syndication/atommedia" xmlns:ostatus="http://ostatus.org/schema/1.0" xmlns:mastodon="http://mastodon.social/schema/1.0"> + <id>tag:overwatch.com,2017-04-27:objectId=4467137:objectType=Status</id> + <published>2017-04-27T13:49:25Z</published> + <updated>2017-04-27T13:49:25Z</updated> + <author> + <id>https://overwatch.com/users/tracer</id> + <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type> + <uri>https://overwatch.com/users/tracer</uri> + <name>tracer</name> + </author> + <activity:object-type>http://activitystrea.ms/schema/1.0/activity</activity:object-type> + <activity:verb>http://activitystrea.ms/schema/1.0/share</activity:verb> + <content type="html">Overwatch rocks</content> + <activity:object> + <id>tag:overwatch.com,2017-04-27:objectId=4467137:objectType=Status</id> + <activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type> + <activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb> + <author> + <id>https://overwatch.com/users/tracer</id> + <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type> + <uri>https://overwatch.com/users/tracer</uri> + <name>tracer</name> + </author> + <content type="html">Overwatch rocks</content> + <link rel="alternate" type="text/html" href="https://overwatch.com/users/tracer/updates/1" /> + </activity:object> +XML + + created_statuses = subject.call(body, actor) + + expect(created_statuses).to eq [] + end + it 'ignores statuses with an out-of-order delete' do sender = Fabricate(:account, username: 'tracer', domain: 'overwatch.com') |