FIX: Don't log a claimed topic database error during tests

We now test the uniqueness validation, but also rescue a DB
exception in case the controller fails this check.
This commit is contained in:
Robin Ward
2020-01-09 12:32:05 -05:00
parent d043a4c6fe
commit dcbe527a82
4 changed files with 21 additions and 6 deletions

View File

@ -6,7 +6,10 @@ class ReviewableClaimedTopicsController < ApplicationController
def create
topic = Topic.find_by(id: params[:reviewable_claimed_topic][:topic_id])
guardian.ensure_can_claim_reviewable_topic!(topic)
ReviewableClaimedTopic.create!(user_id: current_user.id, topic_id: topic.id)
ReviewableClaimedTopic.create(user_id: current_user.id, topic_id: topic.id)
render json: success_json
rescue ActiveRecord::RecordNotUnique
# This is just in case the validation fails under concurrency
render json: success_json
end