mirror of
https://framagit.org/tykayn/mastodon.git
synced 2023-08-25 08:33:12 +02:00
e38fc319dc
* Change account and user fabricators to simplify and improve tests - `Fabricate(:account)` implicitly fabricates an associated `user` if no `domain` attribute is given (an account with `domain: nil` is considered a local account, but no user record was created), unless `user: nil` is passed - `Fabricate(:account, user: Fabricate(:user))` should still be possible but is discouraged. * Fix and refactor tests - avoid passing unneeded attributes to `Fabricate(:user)` or `Fabricate(:account)` - avoid embedding `Fabricate(:user)` into a `Fabricate(:account)` or the other way around - prefer `Fabricate(:user, account_attributes: …)` to `Fabricate(:user, account: Fabricate(:account, …)` - also, some tests were using remote accounts with local user records, which is not representative of production code.
64 lines
2.0 KiB
Ruby
64 lines
2.0 KiB
Ruby
require 'rails_helper'
|
|
|
|
RSpec.describe Api::V1::BlocksController, type: :controller do
|
|
render_views
|
|
|
|
let(:user) { Fabricate(:user) }
|
|
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 } }
|
|
|
|
describe 'GET #index' do
|
|
it 'limits according to limit parameter' do
|
|
2.times.map { Fabricate(:block, account: user.account) }
|
|
get :index, params: { limit: 1 }
|
|
expect(body_as_json.size).to eq 1
|
|
end
|
|
|
|
it 'queries blocks in range according to max_id' do
|
|
blocks = 2.times.map { Fabricate(:block, account: user.account) }
|
|
|
|
get :index, params: { max_id: blocks[1] }
|
|
|
|
expect(body_as_json.size).to eq 1
|
|
expect(body_as_json[0][:id]).to eq blocks[0].target_account_id.to_s
|
|
end
|
|
|
|
it 'queries blocks in range according to since_id' do
|
|
blocks = 2.times.map { Fabricate(:block, account: user.account) }
|
|
|
|
get :index, params: { since_id: blocks[0] }
|
|
|
|
expect(body_as_json.size).to eq 1
|
|
expect(body_as_json[0][:id]).to eq blocks[1].target_account_id.to_s
|
|
end
|
|
|
|
it 'sets pagination header for next path' do
|
|
blocks = 2.times.map { Fabricate(:block, account: user.account) }
|
|
get :index, params: { limit: 1, since_id: blocks[0] }
|
|
expect(response.headers['Link'].find_link(['rel', 'next']).href).to eq api_v1_blocks_url(limit: 1, max_id: blocks[1])
|
|
end
|
|
|
|
it 'sets pagination header for previous path' do
|
|
block = Fabricate(:block, account: user.account)
|
|
get :index
|
|
expect(response.headers['Link'].find_link(['rel', 'prev']).href).to eq api_v1_blocks_url(since_id: block)
|
|
end
|
|
|
|
it 'returns http success' 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
|