2016-02-29 19:42:08 +01:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe AccountsController, type: :controller do
|
2016-09-08 00:33:07 +02:00
|
|
|
render_views
|
|
|
|
|
2019-03-14 05:28:30 +01:00
|
|
|
let(:alice) { Fabricate(:account, username: 'alice', user: Fabricate(:user)) }
|
2018-10-04 12:36:53 +02:00
|
|
|
let(:eve) { Fabricate(:user) }
|
2016-02-29 19:42:08 +01:00
|
|
|
|
|
|
|
describe 'GET #show' do
|
2017-05-23 02:53:01 +02:00
|
|
|
let!(:status1) { Status.create!(account: alice, text: 'Hello world') }
|
|
|
|
let!(:status2) { Status.create!(account: alice, text: 'Boop', thread: status1) }
|
|
|
|
let!(:status3) { Status.create!(account: alice, text: 'Picture!') }
|
|
|
|
let!(:status4) { Status.create!(account: alice, text: 'Mentioning @alice') }
|
2017-08-25 18:50:52 +02:00
|
|
|
let!(:status5) { Status.create!(account: alice, text: 'Kitsune') }
|
|
|
|
let!(:status6) { Status.create!(account: alice, text: 'Neko') }
|
|
|
|
let!(:status7) { Status.create!(account: alice, text: 'Tanuki') }
|
|
|
|
|
|
|
|
let!(:status_pin1) { StatusPin.create!(account: alice, status: status5, created_at: 5.days.ago) }
|
|
|
|
let!(:status_pin2) { StatusPin.create!(account: alice, status: status6, created_at: 2.years.ago) }
|
|
|
|
let!(:status_pin3) { StatusPin.create!(account: alice, status: status7, created_at: 10.minutes.ago) }
|
2017-05-23 02:53:01 +02:00
|
|
|
|
2016-09-08 00:33:07 +02:00
|
|
|
before do
|
2017-11-09 14:36:17 +01:00
|
|
|
alice.block!(eve.account)
|
2016-09-08 00:33:07 +02:00
|
|
|
status3.media_attachments.create!(account: alice, file: fixture_file_upload('files/attachment.jpg', 'image/jpeg'))
|
2016-02-29 19:42:08 +01:00
|
|
|
end
|
|
|
|
|
2017-11-09 14:36:17 +01:00
|
|
|
shared_examples 'responses' do
|
2016-09-08 00:33:07 +02:00
|
|
|
before do
|
2017-11-09 14:36:17 +01:00
|
|
|
sign_in(current_user) if defined? current_user
|
|
|
|
get :show, params: {
|
|
|
|
username: alice.username,
|
|
|
|
max_id: (max_id if defined? max_id),
|
|
|
|
since_id: (since_id if defined? since_id),
|
|
|
|
current_user: (current_user if defined? current_user),
|
|
|
|
}, format: format
|
2017-05-23 02:53:01 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'assigns @account' do
|
|
|
|
expect(assigns(:account)).to eq alice
|
|
|
|
end
|
|
|
|
|
2017-11-09 14:36:17 +01:00
|
|
|
it 'returns http success' do
|
2018-04-21 21:35:07 +02:00
|
|
|
expect(response).to have_http_status(200)
|
2016-09-08 00:33:07 +02:00
|
|
|
end
|
|
|
|
|
2017-11-09 14:36:17 +01:00
|
|
|
it 'returns correct format' do
|
|
|
|
expect(response.content_type).to eq content_type
|
2016-09-08 00:33:07 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-11-09 14:36:17 +01:00
|
|
|
context 'atom' do
|
|
|
|
let(:format) { 'atom' }
|
|
|
|
let(:content_type) { 'application/atom+xml' }
|
2017-02-06 21:14:02 +01:00
|
|
|
|
2017-11-09 14:36:17 +01:00
|
|
|
shared_examples 'responsed streams' do
|
|
|
|
it 'assigns @entries' do
|
|
|
|
entries = assigns(:entries).to_a
|
|
|
|
expect(entries.size).to eq expected_statuses.size
|
|
|
|
entries.each.zip(expected_statuses.each) do |entry, expected_status|
|
|
|
|
expect(entry.status).to eq expected_status
|
|
|
|
end
|
|
|
|
end
|
2017-05-23 02:53:01 +02:00
|
|
|
end
|
|
|
|
|
2017-11-09 14:36:17 +01:00
|
|
|
include_examples 'responses'
|
2017-08-14 04:16:43 +02:00
|
|
|
|
2017-11-09 14:36:17 +01:00
|
|
|
context 'without max_id nor since_id' do
|
|
|
|
let(:expected_statuses) { [status7, status6, status5, status4, status3, status2, status1] }
|
2017-02-06 21:14:02 +01:00
|
|
|
|
2017-11-09 14:36:17 +01:00
|
|
|
include_examples 'responsed streams'
|
2017-09-04 12:53:18 +02:00
|
|
|
end
|
|
|
|
|
2017-11-09 14:36:17 +01:00
|
|
|
context 'with max_id and since_id' do
|
|
|
|
let(:max_id) { status4.stream_entry.id }
|
|
|
|
let(:since_id) { status1.stream_entry.id }
|
|
|
|
let(:expected_statuses) { [status3, status2] }
|
2017-09-04 12:53:18 +02:00
|
|
|
|
2017-11-09 14:36:17 +01:00
|
|
|
include_examples 'responsed streams'
|
2017-09-04 12:53:18 +02:00
|
|
|
end
|
2017-11-09 14:36:17 +01:00
|
|
|
end
|
2017-09-04 12:53:18 +02:00
|
|
|
|
2017-11-09 14:36:17 +01:00
|
|
|
context 'activitystreams2' do
|
|
|
|
let(:format) { 'json' }
|
|
|
|
let(:content_type) { 'application/activity+json' }
|
|
|
|
|
|
|
|
include_examples 'responses'
|
2017-09-04 12:53:18 +02:00
|
|
|
end
|
|
|
|
|
2017-11-09 14:36:17 +01:00
|
|
|
context 'html' do
|
|
|
|
let(:format) { nil }
|
|
|
|
let(:content_type) { 'text/html' }
|
2017-05-23 02:53:01 +02:00
|
|
|
|
2017-11-09 14:36:17 +01:00
|
|
|
shared_examples 'responsed statuses' do
|
|
|
|
it 'assigns @pinned_statuses' do
|
|
|
|
pinned_statuses = assigns(:pinned_statuses).to_a
|
|
|
|
expect(pinned_statuses.size).to eq expected_pinned_statuses.size
|
|
|
|
pinned_statuses.each.zip(expected_pinned_statuses.each) do |pinned_status, expected_pinned_status|
|
|
|
|
expect(pinned_status).to eq expected_pinned_status
|
|
|
|
end
|
|
|
|
end
|
2017-05-23 02:53:01 +02:00
|
|
|
|
2017-11-09 14:36:17 +01:00
|
|
|
it 'assigns @statuses' do
|
|
|
|
statuses = assigns(:statuses).to_a
|
|
|
|
expect(statuses.size).to eq expected_statuses.size
|
|
|
|
statuses.each.zip(expected_statuses.each) do |status, expected_status|
|
|
|
|
expect(status).to eq expected_status
|
|
|
|
end
|
|
|
|
end
|
2016-09-08 00:33:07 +02:00
|
|
|
end
|
|
|
|
|
2017-11-09 14:36:17 +01:00
|
|
|
include_examples 'responses'
|
|
|
|
|
|
|
|
context 'with anonymous visitor' do
|
|
|
|
context 'without since_id nor max_id' do
|
|
|
|
let(:expected_statuses) { [status7, status6, status5, status4, status3, status2, status1] }
|
|
|
|
let(:expected_pinned_statuses) { [status7, status5, status6] }
|
|
|
|
|
|
|
|
include_examples 'responsed statuses'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with since_id nor max_id' do
|
|
|
|
let(:max_id) { status4.id }
|
|
|
|
let(:since_id) { status1.id }
|
|
|
|
let(:expected_statuses) { [status3, status2] }
|
|
|
|
let(:expected_pinned_statuses) { [] }
|
|
|
|
|
|
|
|
include_examples 'responsed statuses'
|
|
|
|
end
|
2017-08-25 18:50:52 +02:00
|
|
|
end
|
|
|
|
|
2017-11-09 14:36:17 +01:00
|
|
|
context 'with blocked visitor' do
|
|
|
|
let(:current_user) { eve }
|
|
|
|
|
|
|
|
context 'without since_id nor max_id' do
|
|
|
|
let(:expected_statuses) { [] }
|
|
|
|
let(:expected_pinned_statuses) { [] }
|
|
|
|
|
|
|
|
include_examples 'responsed statuses'
|
|
|
|
end
|
2016-09-08 00:33:07 +02:00
|
|
|
end
|
2016-02-29 19:42:08 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|