Merge branch 'master' into glitch-soc/tentative-merge
Conflicts: README.md app/controllers/statuses_controller.rb app/lib/feed_manager.rb config/navigation.rb spec/lib/feed_manager_spec.rb Conflicts were resolved by taking both versions for each change. This means the two filter systems (glitch-soc's keyword mutes and tootsuite's custom filters) are in place, which will be changed in a follow-up commit.
This commit is contained in:
@@ -4,7 +4,7 @@ describe Api::V1::Accounts::CredentialsController do
|
||||
render_views
|
||||
|
||||
let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read write') }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
||||
|
||||
context 'with an oauth token' do
|
||||
before do
|
||||
@@ -12,6 +12,8 @@ describe Api::V1::Accounts::CredentialsController do
|
||||
end
|
||||
|
||||
describe 'GET #show' do
|
||||
let(:scopes) { 'read:accounts' }
|
||||
|
||||
it 'returns http success' do
|
||||
get :show
|
||||
expect(response).to have_http_status(200)
|
||||
@@ -19,6 +21,8 @@ describe Api::V1::Accounts::CredentialsController do
|
||||
end
|
||||
|
||||
describe 'PATCH #update' do
|
||||
let(:scopes) { 'write:accounts' }
|
||||
|
||||
describe 'with valid data' do
|
||||
before do
|
||||
allow(ActivityPub::UpdateDistributionWorker).to receive(:perform_async)
|
||||
|
||||
@@ -4,7 +4,7 @@ describe Api::V1::Accounts::FollowerAccountsController do
|
||||
render_views
|
||||
|
||||
let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read') }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read:accounts') }
|
||||
|
||||
before do
|
||||
Fabricate(:follow, target_account: user.account)
|
||||
|
||||
@@ -4,7 +4,7 @@ describe Api::V1::Accounts::FollowingAccountsController do
|
||||
render_views
|
||||
|
||||
let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read') }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read:accounts') }
|
||||
|
||||
before do
|
||||
Fabricate(:follow, account: user.account)
|
||||
|
||||
@@ -4,7 +4,7 @@ describe Api::V1::Accounts::ListsController do
|
||||
render_views
|
||||
|
||||
let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read') }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read:lists') }
|
||||
let(:account) { Fabricate(:account) }
|
||||
let(:list) { Fabricate(:list, account: user.account) }
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ describe Api::V1::Accounts::RelationshipsController do
|
||||
render_views
|
||||
|
||||
let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read') }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read:follows') }
|
||||
|
||||
before do
|
||||
allow(controller).to receive(:doorkeeper_token) { token }
|
||||
|
||||
@@ -4,7 +4,7 @@ RSpec.describe Api::V1::Accounts::SearchController, type: :controller do
|
||||
render_views
|
||||
|
||||
let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read') }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read:accounts') }
|
||||
|
||||
before do
|
||||
allow(controller).to receive(:doorkeeper_token) { token }
|
||||
|
||||
@@ -4,7 +4,7 @@ describe Api::V1::Accounts::StatusesController do
|
||||
render_views
|
||||
|
||||
let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read') }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read:statuses') }
|
||||
|
||||
before do
|
||||
allow(controller).to receive(:doorkeeper_token) { token }
|
||||
|
||||
@@ -3,21 +3,38 @@ require 'rails_helper'
|
||||
RSpec.describe Api::V1::AccountsController, type: :controller do
|
||||
render_views
|
||||
|
||||
let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'follow read') }
|
||||
let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
|
||||
let(:scopes) { '' }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
||||
|
||||
before do
|
||||
allow(controller).to receive(:doorkeeper_token) { token }
|
||||
end
|
||||
|
||||
describe 'GET #show' do
|
||||
it 'returns http success' do
|
||||
get :show, params: { id: user.account.id }
|
||||
expect(response).to have_http_status(200)
|
||||
shared_examples 'forbidden for wrong scope' do |wrong_scope|
|
||||
let(:scopes) { wrong_scope }
|
||||
|
||||
it 'returns http forbidden' do
|
||||
expect(response).to have_http_status(403)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET #show' do
|
||||
let(:scopes) { 'read:accounts' }
|
||||
|
||||
before do
|
||||
get :show, params: { id: user.account.id }
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
|
||||
it_behaves_like 'forbidden for wrong scope', 'write:statuses'
|
||||
end
|
||||
|
||||
describe 'POST #follow' do
|
||||
let(:scopes) { 'write:follows' }
|
||||
let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob', locked: locked)).account }
|
||||
|
||||
before do
|
||||
@@ -41,6 +58,8 @@ RSpec.describe Api::V1::AccountsController, type: :controller do
|
||||
it 'creates a following relation between user and target user' do
|
||||
expect(user.account.following?(other_account)).to be true
|
||||
end
|
||||
|
||||
it_behaves_like 'forbidden for wrong scope', 'read:accounts'
|
||||
end
|
||||
|
||||
context 'with locked account' do
|
||||
@@ -60,10 +79,13 @@ RSpec.describe Api::V1::AccountsController, type: :controller do
|
||||
it 'creates a follow request relation between user and target user' do
|
||||
expect(user.account.requested?(other_account)).to be true
|
||||
end
|
||||
|
||||
it_behaves_like 'forbidden for wrong scope', 'read:accounts'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #unfollow' do
|
||||
let(:scopes) { 'write:follows' }
|
||||
let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
|
||||
|
||||
before do
|
||||
@@ -78,9 +100,12 @@ RSpec.describe Api::V1::AccountsController, type: :controller do
|
||||
it 'removes the following relation between user and target user' do
|
||||
expect(user.account.following?(other_account)).to be false
|
||||
end
|
||||
|
||||
it_behaves_like 'forbidden for wrong scope', 'read:accounts'
|
||||
end
|
||||
|
||||
describe 'POST #block' do
|
||||
let(:scopes) { 'write:blocks' }
|
||||
let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
|
||||
|
||||
before do
|
||||
@@ -99,9 +124,12 @@ RSpec.describe Api::V1::AccountsController, type: :controller do
|
||||
it 'creates a blocking relation' do
|
||||
expect(user.account.blocking?(other_account)).to be true
|
||||
end
|
||||
|
||||
it_behaves_like 'forbidden for wrong scope', 'read:accounts'
|
||||
end
|
||||
|
||||
describe 'POST #unblock' do
|
||||
let(:scopes) { 'write:blocks' }
|
||||
let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
|
||||
|
||||
before do
|
||||
@@ -116,9 +144,12 @@ RSpec.describe Api::V1::AccountsController, type: :controller do
|
||||
it 'removes the blocking relation between user and target user' do
|
||||
expect(user.account.blocking?(other_account)).to be false
|
||||
end
|
||||
|
||||
it_behaves_like 'forbidden for wrong scope', 'read:accounts'
|
||||
end
|
||||
|
||||
describe 'POST #mute' do
|
||||
let(:scopes) { 'write:mutes' }
|
||||
let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
|
||||
|
||||
before do
|
||||
@@ -141,9 +172,12 @@ RSpec.describe Api::V1::AccountsController, type: :controller do
|
||||
it 'mutes notifications' do
|
||||
expect(user.account.muting_notifications?(other_account)).to be true
|
||||
end
|
||||
|
||||
it_behaves_like 'forbidden for wrong scope', 'read:accounts'
|
||||
end
|
||||
|
||||
describe 'POST #mute with notifications set to false' do
|
||||
let(:scopes) { 'write:mutes' }
|
||||
let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
|
||||
|
||||
before do
|
||||
@@ -166,9 +200,12 @@ RSpec.describe Api::V1::AccountsController, type: :controller do
|
||||
it 'does not mute notifications' do
|
||||
expect(user.account.muting_notifications?(other_account)).to be false
|
||||
end
|
||||
|
||||
it_behaves_like 'forbidden for wrong scope', 'read:accounts'
|
||||
end
|
||||
|
||||
describe 'POST #unmute' do
|
||||
let(:scopes) { 'write:mutes' }
|
||||
let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
|
||||
|
||||
before do
|
||||
@@ -183,5 +220,7 @@ RSpec.describe Api::V1::AccountsController, type: :controller do
|
||||
it 'removes the muting relation between user and target user' do
|
||||
expect(user.account.muting?(other_account)).to be false
|
||||
end
|
||||
|
||||
it_behaves_like 'forbidden for wrong scope', 'read:accounts'
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,8 +3,9 @@ require 'rails_helper'
|
||||
RSpec.describe Api::V1::BlocksController, type: :controller do
|
||||
render_views
|
||||
|
||||
let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'follow') }
|
||||
let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
|
||||
let(:scopes) { 'read:blocks' }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
||||
|
||||
before { allow(controller).to receive(:doorkeeper_token) { token } }
|
||||
|
||||
@@ -49,5 +50,14 @@ RSpec.describe Api::V1::BlocksController, type: :controller do
|
||||
get :index
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
|
||||
context 'with wrong scopes' do
|
||||
let(:scopes) { 'write:blocks' }
|
||||
|
||||
it 'returns http forbidden' do
|
||||
get :index
|
||||
expect(response).to have_http_status(403)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,14 +4,24 @@ RSpec.describe Api::V1::DomainBlocksController, type: :controller do
|
||||
render_views
|
||||
|
||||
let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'follow') }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
||||
|
||||
before do
|
||||
user.account.block_domain!('example.com')
|
||||
allow(controller).to receive(:doorkeeper_token) { token }
|
||||
end
|
||||
|
||||
shared_examples 'forbidden for wrong scope' do |wrong_scope|
|
||||
let(:scopes) { wrong_scope }
|
||||
|
||||
it 'returns http forbidden' do
|
||||
expect(response).to have_http_status(403)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET #show' do
|
||||
let(:scopes) { 'read:blocks' }
|
||||
|
||||
before do
|
||||
get :show, params: { limit: 1 }
|
||||
end
|
||||
@@ -23,9 +33,13 @@ RSpec.describe Api::V1::DomainBlocksController, type: :controller do
|
||||
it 'returns blocked domains' do
|
||||
expect(body_as_json.first).to eq 'example.com'
|
||||
end
|
||||
|
||||
it_behaves_like 'forbidden for wrong scope', 'write:statuses'
|
||||
end
|
||||
|
||||
describe 'POST #create' do
|
||||
let(:scopes) { 'write:blocks' }
|
||||
|
||||
before do
|
||||
post :create, params: { domain: 'example.org' }
|
||||
end
|
||||
@@ -37,9 +51,13 @@ RSpec.describe Api::V1::DomainBlocksController, type: :controller do
|
||||
it 'creates a domain block' do
|
||||
expect(user.account.domain_blocking?('example.org')).to be true
|
||||
end
|
||||
|
||||
it_behaves_like 'forbidden for wrong scope', 'write:statuses'
|
||||
end
|
||||
|
||||
describe 'DELETE #destroy' do
|
||||
let(:scopes) { 'write:blocks' }
|
||||
|
||||
before do
|
||||
delete :destroy, params: { domain: 'example.com' }
|
||||
end
|
||||
@@ -51,5 +69,7 @@ RSpec.describe Api::V1::DomainBlocksController, type: :controller do
|
||||
it 'deletes a domain block' do
|
||||
expect(user.account.domain_blocking?('example.com')).to be false
|
||||
end
|
||||
|
||||
it_behaves_like 'forbidden for wrong scope', 'write:statuses'
|
||||
end
|
||||
end
|
||||
|
||||
@@ -45,7 +45,7 @@ RSpec.describe Api::V1::FavouritesController, type: :controller do
|
||||
context 'with read scope and valid resource owner' do
|
||||
before do
|
||||
allow(controller).to receive(:doorkeeper_token) do
|
||||
Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read')
|
||||
Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read:favourites')
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
87
spec/controllers/api/v1/filter_controller_spec.rb
Normal file
87
spec/controllers/api/v1/filter_controller_spec.rb
Normal file
@@ -0,0 +1,87 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Api::V1::FiltersController, type: :controller do
|
||||
render_views
|
||||
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
||||
|
||||
before do
|
||||
allow(controller).to receive(:doorkeeper_token) { token }
|
||||
end
|
||||
|
||||
describe 'GET #index' do
|
||||
let(:scopes) { 'read:filters' }
|
||||
let!(:filter) { Fabricate(:custom_filter, account: user.account) }
|
||||
|
||||
it 'returns http success' do
|
||||
get :index
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #create' do
|
||||
let(:scopes) { 'write:filters' }
|
||||
|
||||
before do
|
||||
post :create, params: { phrase: 'magic', context: %w(home), irreversible: true }
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
|
||||
it 'creates a filter' do
|
||||
filter = user.account.custom_filters.first
|
||||
expect(filter).to_not be_nil
|
||||
expect(filter.phrase).to eq 'magic'
|
||||
expect(filter.context).to eq %w(home)
|
||||
expect(filter.irreversible?).to be true
|
||||
expect(filter.expires_at).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET #show' do
|
||||
let(:scopes) { 'read:filters' }
|
||||
let(:filter) { Fabricate(:custom_filter, account: user.account) }
|
||||
|
||||
it 'returns http success' do
|
||||
get :show, params: { id: filter.id }
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'PUT #update' do
|
||||
let(:scopes) { 'write:filters' }
|
||||
let(:filter) { Fabricate(:custom_filter, account: user.account) }
|
||||
|
||||
before do
|
||||
put :update, params: { id: filter.id, phrase: 'updated' }
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
|
||||
it 'updates the filter' do
|
||||
expect(filter.reload.phrase).to eq 'updated'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'DELETE #destroy' do
|
||||
let(:scopes) { 'write:filters' }
|
||||
let(:filter) { Fabricate(:custom_filter, account: user.account) }
|
||||
|
||||
before do
|
||||
delete :destroy, params: { id: filter.id }
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
|
||||
it 'removes the filter' do
|
||||
expect { filter.reload }.to raise_error ActiveRecord::RecordNotFound
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -4,7 +4,7 @@ RSpec.describe Api::V1::FollowRequestsController, type: :controller do
|
||||
render_views
|
||||
|
||||
let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice', locked: true)) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'follow') }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
||||
let(:follower) { Fabricate(:account, username: 'bob') }
|
||||
|
||||
before do
|
||||
@@ -13,6 +13,8 @@ RSpec.describe Api::V1::FollowRequestsController, type: :controller do
|
||||
end
|
||||
|
||||
describe 'GET #index' do
|
||||
let(:scopes) { 'read:follows' }
|
||||
|
||||
before do
|
||||
get :index, params: { limit: 1 }
|
||||
end
|
||||
@@ -23,6 +25,8 @@ RSpec.describe Api::V1::FollowRequestsController, type: :controller do
|
||||
end
|
||||
|
||||
describe 'POST #authorize' do
|
||||
let(:scopes) { 'write:follows' }
|
||||
|
||||
before do
|
||||
post :authorize, params: { id: follower.id }
|
||||
end
|
||||
@@ -37,6 +41,8 @@ RSpec.describe Api::V1::FollowRequestsController, type: :controller do
|
||||
end
|
||||
|
||||
describe 'POST #reject' do
|
||||
let(:scopes) { 'write:follows' }
|
||||
|
||||
before do
|
||||
post :reject, params: { id: follower.id }
|
||||
end
|
||||
|
||||
@@ -4,7 +4,7 @@ RSpec.describe Api::V1::FollowsController, type: :controller do
|
||||
render_views
|
||||
|
||||
let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'follow') }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'write:follows') }
|
||||
|
||||
before do
|
||||
allow(controller).to receive(:doorkeeper_token) { token }
|
||||
|
||||
@@ -4,7 +4,7 @@ describe Api::V1::Lists::AccountsController do
|
||||
render_views
|
||||
|
||||
let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read write') }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
||||
let(:list) { Fabricate(:list, account: user.account) }
|
||||
|
||||
before do
|
||||
@@ -14,6 +14,8 @@ describe Api::V1::Lists::AccountsController do
|
||||
end
|
||||
|
||||
describe 'GET #index' do
|
||||
let(:scopes) { 'read:lists' }
|
||||
|
||||
it 'returns http success' do
|
||||
get :show, params: { list_id: list.id }
|
||||
|
||||
@@ -22,6 +24,7 @@ describe Api::V1::Lists::AccountsController do
|
||||
end
|
||||
|
||||
describe 'POST #create' do
|
||||
let(:scopes) { 'write:lists' }
|
||||
let(:bob) { Fabricate(:account, username: 'bob') }
|
||||
|
||||
before do
|
||||
@@ -39,6 +42,8 @@ describe Api::V1::Lists::AccountsController do
|
||||
end
|
||||
|
||||
describe 'DELETE #destroy' do
|
||||
let(:scopes) { 'write:lists' }
|
||||
|
||||
before do
|
||||
delete :destroy, params: { list_id: list.id, account_ids: [list.accounts.first.id] }
|
||||
end
|
||||
|
||||
@@ -4,12 +4,14 @@ RSpec.describe Api::V1::ListsController, type: :controller do
|
||||
render_views
|
||||
|
||||
let!(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
|
||||
let!(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read write') }
|
||||
let!(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
||||
let!(:list) { Fabricate(:list, account: user.account) }
|
||||
|
||||
before { allow(controller).to receive(:doorkeeper_token) { token } }
|
||||
|
||||
describe 'GET #index' do
|
||||
let(:scopes) { 'read:lists' }
|
||||
|
||||
it 'returns http success' do
|
||||
get :index
|
||||
expect(response).to have_http_status(200)
|
||||
@@ -17,6 +19,8 @@ RSpec.describe Api::V1::ListsController, type: :controller do
|
||||
end
|
||||
|
||||
describe 'GET #show' do
|
||||
let(:scopes) { 'read:lists' }
|
||||
|
||||
it 'returns http success' do
|
||||
get :show, params: { id: list.id }
|
||||
expect(response).to have_http_status(200)
|
||||
@@ -24,6 +28,8 @@ RSpec.describe Api::V1::ListsController, type: :controller do
|
||||
end
|
||||
|
||||
describe 'POST #create' do
|
||||
let(:scopes) { 'write:lists' }
|
||||
|
||||
before do
|
||||
post :create, params: { title: 'Foo bar' }
|
||||
end
|
||||
@@ -39,6 +45,8 @@ RSpec.describe Api::V1::ListsController, type: :controller do
|
||||
end
|
||||
|
||||
describe 'PUT #update' do
|
||||
let(:scopes) { 'write:lists' }
|
||||
|
||||
before do
|
||||
put :update, params: { id: list.id, title: 'Updated title' }
|
||||
end
|
||||
@@ -53,6 +61,8 @@ RSpec.describe Api::V1::ListsController, type: :controller do
|
||||
end
|
||||
|
||||
describe 'DELETE #destroy' do
|
||||
let(:scopes) { 'write:lists' }
|
||||
|
||||
before do
|
||||
delete :destroy, params: { id: list.id }
|
||||
end
|
||||
|
||||
@@ -4,7 +4,7 @@ RSpec.describe Api::V1::MediaController, type: :controller do
|
||||
render_views
|
||||
|
||||
let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'write') }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'write:media') }
|
||||
|
||||
before do
|
||||
allow(controller).to receive(:doorkeeper_token) { token }
|
||||
|
||||
@@ -4,7 +4,7 @@ RSpec.describe Api::V1::MutesController, type: :controller do
|
||||
render_views
|
||||
|
||||
let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'follow') }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read:mutes') }
|
||||
|
||||
before do
|
||||
Fabricate(:mute, account: user.account, hide_notifications: false)
|
||||
|
||||
@@ -4,7 +4,7 @@ RSpec.describe Api::V1::NotificationsController, type: :controller do
|
||||
render_views
|
||||
|
||||
let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read') }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
||||
let(:other) { Fabricate(:user, account: Fabricate(:account, username: 'bob')) }
|
||||
|
||||
before do
|
||||
@@ -12,6 +12,8 @@ RSpec.describe Api::V1::NotificationsController, type: :controller do
|
||||
end
|
||||
|
||||
describe 'GET #show' do
|
||||
let(:scopes) { 'read:notifications' }
|
||||
|
||||
it 'returns http success' do
|
||||
notification = Fabricate(:notification, account: user.account)
|
||||
get :show, params: { id: notification.id }
|
||||
@@ -21,6 +23,8 @@ RSpec.describe Api::V1::NotificationsController, type: :controller do
|
||||
end
|
||||
|
||||
describe 'POST #dismiss' do
|
||||
let(:scopes) { 'write:notifications' }
|
||||
|
||||
it 'destroys the notification' do
|
||||
notification = Fabricate(:notification, account: user.account)
|
||||
post :dismiss, params: { id: notification.id }
|
||||
@@ -31,6 +35,8 @@ RSpec.describe Api::V1::NotificationsController, type: :controller do
|
||||
end
|
||||
|
||||
describe 'POST #clear' do
|
||||
let(:scopes) { 'write:notifications' }
|
||||
|
||||
it 'clears notifications for the account' do
|
||||
notification = Fabricate(:notification, account: user.account)
|
||||
post :clear
|
||||
@@ -41,6 +47,8 @@ RSpec.describe Api::V1::NotificationsController, type: :controller do
|
||||
end
|
||||
|
||||
describe 'GET #index' do
|
||||
let(:scopes) { 'read:notifications' }
|
||||
|
||||
before do
|
||||
first_status = PostStatusService.new.call(user.account, 'Test')
|
||||
@reblog_of_first_status = ReblogService.new.call(other.account, first_status)
|
||||
|
||||
@@ -6,13 +6,15 @@ RSpec.describe Api::V1::ReportsController, type: :controller do
|
||||
render_views
|
||||
|
||||
let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read write') }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
||||
|
||||
before do
|
||||
allow(controller).to receive(:doorkeeper_token) { token }
|
||||
end
|
||||
|
||||
describe 'GET #index' do
|
||||
let(:scopes) { 'read:reports' }
|
||||
|
||||
it 'returns http success' do
|
||||
get :index
|
||||
|
||||
@@ -21,6 +23,7 @@ RSpec.describe Api::V1::ReportsController, type: :controller do
|
||||
end
|
||||
|
||||
describe 'POST #create' do
|
||||
let(:scopes) { 'write:reports' }
|
||||
let!(:status) { Fabricate(:status) }
|
||||
let!(:admin) { Fabricate(:user, admin: true) }
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ RSpec.describe Api::V1::SearchController, type: :controller do
|
||||
render_views
|
||||
|
||||
let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read') }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read:search') }
|
||||
|
||||
before do
|
||||
allow(controller).to receive(:doorkeeper_token) { token }
|
||||
|
||||
@@ -5,7 +5,7 @@ RSpec.describe Api::V1::Statuses::FavouritedByAccountsController, type: :control
|
||||
|
||||
let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
|
||||
let(:app) { Fabricate(:application, name: 'Test app', website: 'http://testapp.com') }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, application: app) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, application: app, scopes: 'read:accounts') }
|
||||
|
||||
context 'with an oauth token' do
|
||||
before do
|
||||
|
||||
@@ -7,7 +7,7 @@ describe Api::V1::Statuses::FavouritesController do
|
||||
|
||||
let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
|
||||
let(:app) { Fabricate(:application, name: 'Test app', website: 'http://testapp.com') }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'write', application: app) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'write:favourites', application: app) }
|
||||
|
||||
context 'with an oauth token' do
|
||||
before do
|
||||
|
||||
@@ -7,7 +7,7 @@ describe Api::V1::Statuses::MutesController do
|
||||
|
||||
let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
|
||||
let(:app) { Fabricate(:application, name: 'Test app', website: 'http://testapp.com') }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'write', application: app) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'write:mutes', application: app) }
|
||||
|
||||
context 'with an oauth token' do
|
||||
before do
|
||||
|
||||
@@ -7,7 +7,7 @@ describe Api::V1::Statuses::PinsController do
|
||||
|
||||
let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
|
||||
let(:app) { Fabricate(:application, name: 'Test app', website: 'http://testapp.com') }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'write', application: app) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'write:accounts', application: app) }
|
||||
|
||||
context 'with an oauth token' do
|
||||
before do
|
||||
|
||||
@@ -5,7 +5,7 @@ RSpec.describe Api::V1::Statuses::RebloggedByAccountsController, type: :controll
|
||||
|
||||
let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
|
||||
let(:app) { Fabricate(:application, name: 'Test app', website: 'http://testapp.com') }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, application: app) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, application: app, scopes: 'read:accounts') }
|
||||
|
||||
context 'with an oauth token' do
|
||||
before do
|
||||
|
||||
@@ -7,7 +7,7 @@ describe Api::V1::Statuses::ReblogsController do
|
||||
|
||||
let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
|
||||
let(:app) { Fabricate(:application, name: 'Test app', website: 'http://testapp.com') }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'write', application: app) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'write:statuses', application: app) }
|
||||
|
||||
context 'with an oauth token' do
|
||||
before do
|
||||
|
||||
@@ -5,7 +5,7 @@ RSpec.describe Api::V1::StatusesController, type: :controller do
|
||||
|
||||
let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
|
||||
let(:app) { Fabricate(:application, name: 'Test app', website: 'http://testapp.com') }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, application: app, scopes: 'write') }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, application: app, scopes: scopes) }
|
||||
|
||||
context 'with an oauth token' do
|
||||
before do
|
||||
@@ -13,6 +13,7 @@ RSpec.describe Api::V1::StatusesController, type: :controller do
|
||||
end
|
||||
|
||||
describe 'GET #show' do
|
||||
let(:scopes) { 'read:statuses' }
|
||||
let(:status) { Fabricate(:status, account: user.account) }
|
||||
|
||||
it 'returns http success' do
|
||||
@@ -22,6 +23,7 @@ RSpec.describe Api::V1::StatusesController, type: :controller do
|
||||
end
|
||||
|
||||
describe 'GET #context' do
|
||||
let(:scopes) { 'read:statuses' }
|
||||
let(:status) { Fabricate(:status, account: user.account) }
|
||||
|
||||
before do
|
||||
@@ -35,6 +37,8 @@ RSpec.describe Api::V1::StatusesController, type: :controller do
|
||||
end
|
||||
|
||||
describe 'POST #create' do
|
||||
let(:scopes) { 'write:statuses' }
|
||||
|
||||
before do
|
||||
post :create, params: { status: 'Hello world' }
|
||||
end
|
||||
@@ -45,6 +49,7 @@ RSpec.describe Api::V1::StatusesController, type: :controller do
|
||||
end
|
||||
|
||||
describe 'DELETE #destroy' do
|
||||
let(:scopes) { 'write:statuses' }
|
||||
let(:status) { Fabricate(:status, account: user.account) }
|
||||
|
||||
before do
|
||||
|
||||
35
spec/controllers/api/v1/suggestions_controller_spec.rb
Normal file
35
spec/controllers/api/v1/suggestions_controller_spec.rb
Normal file
@@ -0,0 +1,35 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Api::V1::SuggestionsController, type: :controller do
|
||||
render_views
|
||||
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read write') }
|
||||
|
||||
before do
|
||||
allow(controller).to receive(:doorkeeper_token) { token }
|
||||
end
|
||||
|
||||
describe 'GET #index' do
|
||||
let(:bob) { Fabricate(:account) }
|
||||
let(:jeff) { Fabricate(:account) }
|
||||
|
||||
before do
|
||||
PotentialFriendshipTracker.record(user.account_id, bob.id, :reblog)
|
||||
PotentialFriendshipTracker.record(user.account_id, jeff.id, :favourite)
|
||||
|
||||
get :index
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
|
||||
it 'returns accounts' do
|
||||
json = body_as_json
|
||||
|
||||
expect(json.size).to be >= 1
|
||||
expect(json.map { |i| i[:id] }).to include *[bob, jeff].map { |i| i.id.to_s }
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -12,7 +12,7 @@ describe Api::V1::Timelines::HomeController do
|
||||
end
|
||||
|
||||
context 'with a user context' do
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read') }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read:statuses') }
|
||||
|
||||
describe 'GET #show' do
|
||||
before do
|
||||
|
||||
@@ -13,7 +13,7 @@ describe Api::V1::Timelines::ListController do
|
||||
end
|
||||
|
||||
context 'with a user context' do
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read') }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read:lists') }
|
||||
|
||||
describe 'GET #show' do
|
||||
before do
|
||||
|
||||
22
spec/controllers/api/v2/search_controller_spec.rb
Normal file
22
spec/controllers/api/v2/search_controller_spec.rb
Normal file
@@ -0,0 +1,22 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Api::V2::SearchController, type: :controller do
|
||||
render_views
|
||||
|
||||
let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read:search') }
|
||||
|
||||
before do
|
||||
allow(controller).to receive(:doorkeeper_token) { token }
|
||||
end
|
||||
|
||||
describe 'GET #index' do
|
||||
it 'returns http success' do
|
||||
get :index, params: { q: 'test' }
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
end
|
||||
6
spec/fabricators/custom_filter_fabricator.rb
Normal file
6
spec/fabricators/custom_filter_fabricator.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
Fabricator(:custom_filter) do
|
||||
account
|
||||
expires_at nil
|
||||
phrase 'discourse'
|
||||
context %w(home notifications)
|
||||
end
|
||||
@@ -195,6 +195,30 @@ RSpec.describe FeedManager do
|
||||
|
||||
expect(FeedManager.instance.filter?(:home, status, alice.id)).to be false
|
||||
end
|
||||
|
||||
context 'for irreversibly muted phrases' do
|
||||
it 'considers word boundaries when matching' do
|
||||
alice.custom_filters.create!(phrase: 'bob', context: %w(home), irreversible: true)
|
||||
alice.follow!(jeff)
|
||||
status = Fabricate(:status, text: 'bobcats', account: jeff)
|
||||
expect(FeedManager.instance.filter?(:home, status, alice.id)).to be_falsy
|
||||
end
|
||||
|
||||
it 'returns true if phrase is contained' do
|
||||
alice.custom_filters.create!(phrase: 'farts', context: %w(home public), irreversible: true)
|
||||
alice.custom_filters.create!(phrase: 'pop tarts', context: %w(home), irreversible: true)
|
||||
alice.follow!(jeff)
|
||||
status = Fabricate(:status, text: 'i sure like POP TARts', account: jeff)
|
||||
expect(FeedManager.instance.filter?(:home, status, alice.id)).to be true
|
||||
end
|
||||
|
||||
it 'matches substrings if whole_word is false' do
|
||||
alice.custom_filters.create!(phrase: 'take', context: %w(home), whole_word: false, irreversible: true)
|
||||
alice.follow!(jeff)
|
||||
status = Fabricate(:status, text: 'shiitake', account: jeff)
|
||||
expect(FeedManager.instance.filter?(:home, status, alice.id)).to be true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'for mentions feed' do
|
||||
|
||||
@@ -454,77 +454,6 @@ RSpec.describe Account, type: :model do
|
||||
end
|
||||
end
|
||||
|
||||
describe '.triadic_closures' do
|
||||
let!(:me) { Fabricate(:account) }
|
||||
let!(:friend) { Fabricate(:account) }
|
||||
let!(:friends_friend) { Fabricate(:account) }
|
||||
let!(:both_follow) { Fabricate(:account) }
|
||||
|
||||
before do
|
||||
me.follow!(friend)
|
||||
friend.follow!(friends_friend)
|
||||
|
||||
me.follow!(both_follow)
|
||||
friend.follow!(both_follow)
|
||||
end
|
||||
|
||||
it 'finds accounts you dont follow which are followed by accounts you do follow' do
|
||||
expect(described_class.triadic_closures(me)).to eq [friends_friend]
|
||||
end
|
||||
|
||||
it 'limits by 5 with offset 0 by defualt' do
|
||||
first_degree = 6.times.map { Fabricate(:account) }
|
||||
matches = 5.times.map { Fabricate(:account) }
|
||||
first_degree.each { |account| me.follow!(account) }
|
||||
matches.each do |match|
|
||||
first_degree.each { |account| account.follow!(match) }
|
||||
first_degree.shift
|
||||
end
|
||||
|
||||
expect(described_class.triadic_closures(me)).to eq matches
|
||||
end
|
||||
|
||||
it 'accepts arbitrary limits' do
|
||||
another_friend = Fabricate(:account)
|
||||
higher_friends_friend = Fabricate(:account)
|
||||
me.follow!(another_friend)
|
||||
friend.follow!(higher_friends_friend)
|
||||
another_friend.follow!(higher_friends_friend)
|
||||
|
||||
expect(described_class.triadic_closures(me, limit: 1)).to eq [higher_friends_friend]
|
||||
end
|
||||
|
||||
it 'acceps arbitrary offset' do
|
||||
another_friend = Fabricate(:account)
|
||||
higher_friends_friend = Fabricate(:account)
|
||||
me.follow!(another_friend)
|
||||
friend.follow!(higher_friends_friend)
|
||||
another_friend.follow!(higher_friends_friend)
|
||||
|
||||
expect(described_class.triadic_closures(me, offset: 1)).to eq [friends_friend]
|
||||
end
|
||||
|
||||
context 'when you block account' do
|
||||
before do
|
||||
me.block!(friends_friend)
|
||||
end
|
||||
|
||||
it 'rejects blocked accounts' do
|
||||
expect(described_class.triadic_closures(me)).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
context 'when you mute account' do
|
||||
before do
|
||||
me.mute!(friends_friend)
|
||||
end
|
||||
|
||||
it 'rejects muted accounts' do
|
||||
expect(described_class.triadic_closures(me)).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#statuses_count' do
|
||||
subject { Fabricate(:account) }
|
||||
|
||||
|
||||
5
spec/models/custom_filter_spec.rb
Normal file
5
spec/models/custom_filter_spec.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe CustomFilter, type: :model do
|
||||
|
||||
end
|
||||
@@ -30,9 +30,7 @@ describe 'stream_entries/show.html.haml', without_verify_partial_doubles: true d
|
||||
|
||||
mf2 = Microformats.parse(rendered)
|
||||
|
||||
expect(mf2.entry.name.to_s).to eq status.text
|
||||
expect(mf2.entry.url.to_s).not_to be_empty
|
||||
|
||||
expect(mf2.entry.author.name.to_s).to eq alice.display_name
|
||||
expect(mf2.entry.author.url.to_s).not_to be_empty
|
||||
end
|
||||
@@ -56,9 +54,7 @@ describe 'stream_entries/show.html.haml', without_verify_partial_doubles: true d
|
||||
|
||||
mf2 = Microformats.parse(rendered)
|
||||
|
||||
expect(mf2.entry.name.to_s).to eq reply.text
|
||||
expect(mf2.entry.url.to_s).not_to be_empty
|
||||
|
||||
expect(mf2.entry.comment.url.to_s).not_to be_empty
|
||||
expect(mf2.entry.comment.author.name.to_s).to eq carl.display_name
|
||||
expect(mf2.entry.comment.author.url.to_s).not_to be_empty
|
||||
|
||||
Reference in New Issue
Block a user