From a74f40ecfcfb2d9fc6ef932985cc0ae380d16db5 Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Sun, 1 Jan 2023 21:21:14 +0100 Subject: [PATCH] Add test for answer uniqueness --- spec/integration/answer_uniqueness_spec.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 spec/integration/answer_uniqueness_spec.rb diff --git a/spec/integration/answer_uniqueness_spec.rb b/spec/integration/answer_uniqueness_spec.rb new file mode 100644 index 00000000..c305e361 --- /dev/null +++ b/spec/integration/answer_uniqueness_spec.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +require "rails_helper" + +describe "Answer uniqueness" do + let(:user) { FactoryBot.build(:user) } + let(:question) { FactoryBot.create(:question) } + + subject { 2.times { user.answer(question, "random") } } + + it "does not allow answering the same question twice" do + expect{ subject }.to raise_error(ActiveRecord::RecordInvalid) + end +end