Add questions with mutiple answers to polls public interface

The `reload` method added to max_votes validation is needed because the
author gets here with some changes because of the around_action
`switch_locale`, which adds some changes to the current user record and
therefore, the lock method raises an exception when trying to lock it
requiring us to save or discard those record changes.
This commit is contained in:
decabeza
2022-09-02 16:41:17 +02:00
committed by Senén Rodero Rodríguez
parent 3da4112d94
commit 36e452437e
11 changed files with 121 additions and 5 deletions

View File

@@ -33,6 +33,20 @@ describe Polls::Questions::AnswersComponent do
expect(page).to have_css "button[aria-pressed='true']", text: "Yes"
end
it "renders disabled buttons when max votes is reached" do
user = create(:user, :verified)
question = create(:poll_question_multiple, :abc, max_votes: 2, author: user)
create(:poll_answer, author: user, question: question, answer: "Answer A")
create(:poll_answer, author: user, question: question, answer: "Answer C")
sign_in(user)
render_inline Polls::Questions::AnswersComponent.new(question)
expect(page).to have_button "You have voted Answer A"
expect(page).to have_button "Vote Answer B", disabled: true
expect(page).to have_button "You have voted Answer C"
end
it "when user is not signed in, renders answers links pointing to user sign in path" do
render_inline Polls::Questions::AnswersComponent.new(question)