Browse Source

Fix POST /api/v1/follows error when already following (#4878)

master
Eugen Rochko 7 years ago
committed by GitHub
parent
commit
c450ddb613
2 changed files with 11 additions and 0 deletions
  1. +6
    -0
      app/controllers/api/v1/follows_controller.rb
  2. +5
    -0
      spec/controllers/api/v1/follows_controller_spec.rb

+ 6
- 0
app/controllers/api/v1/follows_controller.rb View File

@ -10,6 +10,12 @@ class Api::V1::FollowsController < Api::BaseController
raise ActiveRecord::RecordNotFound if follow_params[:uri].blank? raise ActiveRecord::RecordNotFound if follow_params[:uri].blank?
@account = FollowService.new.call(current_user.account, target_uri).try(:target_account) @account = FollowService.new.call(current_user.account, target_uri).try(:target_account)
if @account.nil?
username, domain = target_uri.split('@')
@account = Account.find_remote!(username, domain)
end
render json: @account, serializer: REST::AccountSerializer render json: @account, serializer: REST::AccountSerializer
end end

+ 5
- 0
spec/controllers/api/v1/follows_controller_spec.rb View File

@ -42,5 +42,10 @@ RSpec.describe Api::V1::FollowsController, type: :controller do
it 'subscribes to remote hub' do it 'subscribes to remote hub' do
expect(a_request(:post, "https://quitter.no/main/push/hub")).to have_been_made expect(a_request(:post, "https://quitter.no/main/push/hub")).to have_been_made
end end
it 'returns http success if already following, too' do
post :create, params: { uri: 'gargron@quitter.no' }
expect(response).to have_http_status(:success)
end
end end
end end

Loading…
Cancel
Save