Fix exception creating an answer without an author
We were getting `undefined method `lock!' for nil:NilClass` when the question allowed multiple answers.
This commit is contained in:
@@ -36,7 +36,7 @@ class Poll::Answer < ApplicationRecord
|
||||
private
|
||||
|
||||
def max_votes
|
||||
return if !question || question&.unique? || persisted?
|
||||
return if !question || !author || question&.unique? || persisted?
|
||||
|
||||
author.lock!
|
||||
|
||||
|
||||
@@ -18,6 +18,13 @@ describe Poll::Answer do
|
||||
expect(answer).not_to be_valid
|
||||
end
|
||||
|
||||
it "is not valid without an author when multiple answers are allowed" do
|
||||
answer.author = nil
|
||||
answer.question = create(:poll_question_multiple)
|
||||
|
||||
expect(answer).not_to be_valid
|
||||
end
|
||||
|
||||
it "is not valid without an answer" do
|
||||
answer.answer = nil
|
||||
expect(answer).not_to be_valid
|
||||
|
||||
Reference in New Issue
Block a user