follows_controller_spec.rb 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. require 'rails_helper'
  2. RSpec.describe Api::V1::FollowsController, 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: 'write:follows') }
  6. before do
  7. allow(controller).to receive(:doorkeeper_token) { token }
  8. end
  9. describe 'POST #create' do
  10. before do
  11. stub_request(:get, "https://quitter.no/.well-known/host-meta").to_return(request_fixture('.host-meta.txt'))
  12. stub_request(:get, "https://quitter.no/.well-known/webfinger?resource=acct:gargron@quitter.no").to_return(request_fixture('webfinger.txt'))
  13. stub_request(:head, "https://quitter.no/api/statuses/user_timeline/7477.atom").to_return(:status => 405, :body => "", :headers => {})
  14. stub_request(:get, "https://quitter.no/api/statuses/user_timeline/7477.atom").to_return(request_fixture('feed.txt'))
  15. stub_request(:get, "https://quitter.no/avatar/7477-300-20160211190340.png").to_return(request_fixture('avatar.txt'))
  16. stub_request(:post, "https://quitter.no/main/push/hub").to_return(:status => 200, :body => "", :headers => {})
  17. stub_request(:post, "https://quitter.no/main/salmon/user/7477").to_return(:status => 200, :body => "", :headers => {})
  18. post :create, params: { uri: 'gargron@quitter.no' }
  19. end
  20. it 'returns http success' do
  21. expect(response).to have_http_status(200)
  22. end
  23. it 'creates account for remote user' do
  24. expect(Account.find_by(username: 'gargron', domain: 'quitter.no')).to_not be_nil
  25. end
  26. it 'creates a follow relation between user and remote user' do
  27. expect(user.account.following?(Account.find_by(username: 'gargron', domain: 'quitter.no'))).to be true
  28. end
  29. it 'sends a salmon slap to the remote user' do
  30. expect(a_request(:post, "https://quitter.no/main/salmon/user/7477")).to have_been_made
  31. end
  32. it 'subscribes to remote hub' do
  33. expect(a_request(:post, "https://quitter.no/main/push/hub")).to have_been_made
  34. end
  35. it 'returns http success if already following, too' do
  36. post :create, params: { uri: 'gargron@quitter.no' }
  37. expect(response).to have_http_status(200)
  38. end
  39. end
  40. end