From 51a33ce77a32b85eaff37670c40a497aaef13e18 Mon Sep 17 00:00:00 2001
From: Claire <claire.github-309c@sitedethib.com>
Date: Mon, 21 Nov 2022 10:35:09 +0100
Subject: [PATCH] Fix not being able to follow more than one hashtag (#21285)

Fixes regression from #20860
---
 app/controllers/api/v1/tags_controller.rb       | 2 +-
 spec/controllers/api/v1/tags_controller_spec.rb | 4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/app/controllers/api/v1/tags_controller.rb b/app/controllers/api/v1/tags_controller.rb
index 0966ee469..272362c31 100644
--- a/app/controllers/api/v1/tags_controller.rb
+++ b/app/controllers/api/v1/tags_controller.rb
@@ -12,7 +12,7 @@ class Api::V1::TagsController < Api::BaseController
   end
 
   def follow
-    TagFollow.first_or_create!(tag: @tag, account: current_account, rate_limit: true)
+    TagFollow.create_with(rate_limit: true).find_or_create_by!(tag: @tag, account: current_account)
     render json: @tag, serializer: REST::TagSerializer
   end
 
diff --git a/spec/controllers/api/v1/tags_controller_spec.rb b/spec/controllers/api/v1/tags_controller_spec.rb
index ac42660df..216faad87 100644
--- a/spec/controllers/api/v1/tags_controller_spec.rb
+++ b/spec/controllers/api/v1/tags_controller_spec.rb
@@ -33,7 +33,11 @@ RSpec.describe Api::V1::TagsController, type: :controller do
   end
 
   describe 'POST #follow' do
+    let!(:unrelated_tag) { Fabricate(:tag) }
+
     before do
+      TagFollow.create!(account: user.account, tag: unrelated_tag)
+
       post :follow, params: { id: name }
     end