From 9b5470cfd39fd780ee25e8ccee5be2d74333d464 Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Sun, 1 Jan 2023 21:30:41 +0100 Subject: [PATCH] Appease the dog overlords --- app/models/answer.rb | 4 ++++ spec/integration/answer_uniqueness_spec.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/answer.rb b/app/models/answer.rb index 76aeffb0..587db426 100644 --- a/app/models/answer.rb +++ b/app/models/answer.rb @@ -8,7 +8,11 @@ class Answer < ApplicationRecord has_many :subscriptions, dependent: :destroy has_many :comment_smiles, through: :comments, source: :smiles + # rubocop:disable Rails/UniqueValidationWithoutIndex + # This cop is disabled here because there already are questions with + # multiple answers. Adding an index would break things database-side validates :question_id, uniqueness: { scope: :user_id } + # rubocop:enable Rails/UniqueValidationWithoutIndex # rubocop:disable Rails/SkipsModelValidations after_create do diff --git a/spec/integration/answer_uniqueness_spec.rb b/spec/integration/answer_uniqueness_spec.rb index c305e361..c1f42500 100644 --- a/spec/integration/answer_uniqueness_spec.rb +++ b/spec/integration/answer_uniqueness_spec.rb @@ -9,6 +9,6 @@ describe "Answer uniqueness" do subject { 2.times { user.answer(question, "random") } } it "does not allow answering the same question twice" do - expect{ subject }.to raise_error(ActiveRecord::RecordInvalid) + expect { subject }.to raise_error(ActiveRecord::RecordInvalid) end end