The code powering m.abunchtell.com https://m.abunchtell.com
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

64 строки
2.1 KiB

  1. require 'rails_helper'
  2. RSpec.describe Api::V1::BlocksController, type: :controller do
  3. render_views
  4. let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
  5. let(:scopes) { 'read:blocks' }
  6. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
  7. before { allow(controller).to receive(:doorkeeper_token) { token } }
  8. describe 'GET #index' do
  9. it 'limits according to limit parameter' do
  10. 2.times.map { Fabricate(:block, account: user.account) }
  11. get :index, params: { limit: 1 }
  12. expect(body_as_json.size).to eq 1
  13. end
  14. it 'queries blocks in range according to max_id' do
  15. blocks = 2.times.map { Fabricate(:block, account: user.account) }
  16. get :index, params: { max_id: blocks[1] }
  17. expect(body_as_json.size).to eq 1
  18. expect(body_as_json[0][:id]).to eq blocks[0].target_account_id.to_s
  19. end
  20. it 'queries blocks in range according to since_id' do
  21. blocks = 2.times.map { Fabricate(:block, account: user.account) }
  22. get :index, params: { since_id: blocks[0] }
  23. expect(body_as_json.size).to eq 1
  24. expect(body_as_json[0][:id]).to eq blocks[1].target_account_id.to_s
  25. end
  26. it 'sets pagination header for next path' do
  27. blocks = 2.times.map { Fabricate(:block, account: user.account) }
  28. get :index, params: { limit: 1, since_id: blocks[0] }
  29. expect(response.headers['Link'].find_link(['rel', 'next']).href).to eq api_v1_blocks_url(limit: 1, max_id: blocks[1])
  30. end
  31. it 'sets pagination header for previous path' do
  32. block = Fabricate(:block, account: user.account)
  33. get :index
  34. expect(response.headers['Link'].find_link(['rel', 'prev']).href).to eq api_v1_blocks_url(since_id: block)
  35. end
  36. it 'returns http success' do
  37. get :index
  38. expect(response).to have_http_status(200)
  39. end
  40. context 'with wrong scopes' do
  41. let(:scopes) { 'write:blocks' }
  42. it 'returns http forbidden' do
  43. get :index
  44. expect(response).to have_http_status(403)
  45. end
  46. end
  47. end
  48. end