Merge upstream 2.0ish #165
This commit is contained in:
@@ -46,8 +46,8 @@ RSpec.describe Api::SalmonController, type: :controller do
|
||||
post :update, params: { id: account.id }
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
expect(response).to have_http_status(202)
|
||||
it 'returns http client error' do
|
||||
expect(response).to have_http_status(400)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
43
spec/controllers/api/v1/apps/credentials_controller_spec.rb
Normal file
43
spec/controllers/api/v1/apps/credentials_controller_spec.rb
Normal file
@@ -0,0 +1,43 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe Api::V1::Apps::CredentialsController do
|
||||
render_views
|
||||
|
||||
let(:token) { Fabricate(:accessible_access_token, scopes: 'read', application: Fabricate(:application)) }
|
||||
|
||||
context 'with an oauth token' do
|
||||
before do
|
||||
allow(controller).to receive(:doorkeeper_token) { token }
|
||||
end
|
||||
|
||||
describe 'GET #show' do
|
||||
before do
|
||||
get :show
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
|
||||
it 'does not contain client credentials' do
|
||||
json = body_as_json
|
||||
|
||||
expect(json).to_not have_key(:client_secret)
|
||||
expect(json).to_not have_key(:client_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'without an oauth token' do
|
||||
before do
|
||||
allow(controller).to receive(:doorkeeper_token) { nil }
|
||||
end
|
||||
|
||||
describe 'GET #show' do
|
||||
it 'returns http unauthorized' do
|
||||
get :show
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@@ -6,15 +6,47 @@ RSpec.describe Api::V1::BlocksController, type: :controller do
|
||||
let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'follow') }
|
||||
|
||||
before do
|
||||
Fabricate(:block, account: user.account)
|
||||
allow(controller).to receive(:doorkeeper_token) { token }
|
||||
end
|
||||
before { allow(controller).to receive(:doorkeeper_token) { token } }
|
||||
|
||||
describe 'GET #index' do
|
||||
it 'returns http success' 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(:success)
|
||||
end
|
||||
end
|
||||
|
@@ -101,4 +101,33 @@ RSpec.describe Api::V1::MediaController, type: :controller do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'PUT #update' do
|
||||
context 'when somebody else\'s' do
|
||||
let(:media) { Fabricate(:media_attachment, status: nil) }
|
||||
|
||||
it 'returns http not found' do
|
||||
put :update, params: { id: media.id, description: 'Lorem ipsum!!!' }
|
||||
expect(response).to have_http_status(:not_found)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when not attached to a status' do
|
||||
let(:media) { Fabricate(:media_attachment, status: nil, account: user.account) }
|
||||
|
||||
it 'updates the description' do
|
||||
put :update, params: { id: media.id, description: 'Lorem ipsum!!!' }
|
||||
expect(media.reload.description).to eq 'Lorem ipsum!!!'
|
||||
end
|
||||
end
|
||||
|
||||
context 'when attached to a status' do
|
||||
let(:media) { Fabricate(:media_attachment, status: Fabricate(:status), account: user.account) }
|
||||
|
||||
it 'returns http not found' do
|
||||
put :update, params: { id: media.id, description: 'Lorem ipsum!!!' }
|
||||
expect(response).to have_http_status(:not_found)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user