diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2017-09-10 15:09:06 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-10 15:09:06 +0200 |
commit | c450ddb6134602ecc2917c493240e55e8773520b (patch) | |
tree | 46b9bcaa2180463cfc77a22372840211b80fe708 | |
parent | 15b886a6f0b0b9cdb3a5d938a7ec5c902d65410d (diff) |
Fix POST /api/v1/follows error when already following (#4878)
-rw-r--r-- | app/controllers/api/v1/follows_controller.rb | 6 | ||||
-rw-r--r-- | spec/controllers/api/v1/follows_controller_spec.rb | 5 |
2 files changed, 11 insertions, 0 deletions
diff --git a/app/controllers/api/v1/follows_controller.rb b/app/controllers/api/v1/follows_controller.rb index e01ae5c01..5a2b2f32f 100644 --- a/app/controllers/api/v1/follows_controller.rb +++ b/app/controllers/api/v1/follows_controller.rb @@ -10,6 +10,12 @@ class Api::V1::FollowsController < Api::BaseController raise ActiveRecord::RecordNotFound if follow_params[:uri].blank? @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 end diff --git a/spec/controllers/api/v1/follows_controller_spec.rb b/spec/controllers/api/v1/follows_controller_spec.rb index b5e1d16dd..ea9e76d68 100644 --- a/spec/controllers/api/v1/follows_controller_spec.rb +++ b/spec/controllers/api/v1/follows_controller_spec.rb @@ -42,5 +42,10 @@ RSpec.describe Api::V1::FollowsController, type: :controller do it 'subscribes to remote hub' do expect(a_request(:post, "https://quitter.no/main/push/hub")).to have_been_made 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 |