The code powering m.abunchtell.com https://m.abunchtell.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

76 regels
1.8 KiB

  1. require 'rails_helper'
  2. RSpec.describe Api::V1::DomainBlocksController, type: :controller do
  3. render_views
  4. let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
  5. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
  6. before do
  7. user.account.block_domain!('example.com')
  8. allow(controller).to receive(:doorkeeper_token) { token }
  9. end
  10. shared_examples 'forbidden for wrong scope' do |wrong_scope|
  11. let(:scopes) { wrong_scope }
  12. it 'returns http forbidden' do
  13. expect(response).to have_http_status(403)
  14. end
  15. end
  16. describe 'GET #show' do
  17. let(:scopes) { 'read:blocks' }
  18. before do
  19. get :show, params: { limit: 1 }
  20. end
  21. it 'returns http success' do
  22. expect(response).to have_http_status(200)
  23. end
  24. it 'returns blocked domains' do
  25. expect(body_as_json.first).to eq 'example.com'
  26. end
  27. it_behaves_like 'forbidden for wrong scope', 'write:statuses'
  28. end
  29. describe 'POST #create' do
  30. let(:scopes) { 'write:blocks' }
  31. before do
  32. post :create, params: { domain: 'example.org' }
  33. end
  34. it 'returns http success' do
  35. expect(response).to have_http_status(200)
  36. end
  37. it 'creates a domain block' do
  38. expect(user.account.domain_blocking?('example.org')).to be true
  39. end
  40. it_behaves_like 'forbidden for wrong scope', 'write:statuses'
  41. end
  42. describe 'DELETE #destroy' do
  43. let(:scopes) { 'write:blocks' }
  44. before do
  45. delete :destroy, params: { domain: 'example.com' }
  46. end
  47. it 'returns http success' do
  48. expect(response).to have_http_status(200)
  49. end
  50. it 'deletes a domain block' do
  51. expect(user.account.domain_blocking?('example.com')).to be false
  52. end
  53. it_behaves_like 'forbidden for wrong scope', 'write:statuses'
  54. end
  55. end