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

@@ -0,0 +1,69 @@
require "rails_helper"
describe "Poll Votation Type" do
let(:author) { create(:user, :level_two) }
before do
login_as(author)
end
scenario "Unique answer" do
question = create(:poll_question_unique, :yes_no)
visit poll_path(question.poll)
expect(page).to have_content "You can select a maximum of 1 answer."
expect(page).to have_content(question.title)
expect(page).to have_button("Vote Yes")
expect(page).to have_button("Vote No")
within "#poll_question_#{question.id}_answers" do
click_button "Yes"
expect(page).to have_button("You have voted Yes")
expect(page).to have_button("Vote No")
click_button "No"
expect(page).to have_button("Vote Yes")
expect(page).to have_button("You have voted No")
end
end
scenario "Multiple answers" do
question = create(:poll_question_multiple, :abc, max_votes: 2)
visit poll_path(question.poll)
expect(page).to have_content "You can select a maximum of 2 answers."
expect(page).to have_content(question.title)
expect(page).to have_button("Vote Answer A")
expect(page).to have_button("Vote Answer B")
expect(page).to have_button("Vote Answer C")
within "#poll_question_#{question.id}_answers" do
click_button "Vote Answer A"
expect(page).to have_button("You have voted Answer A")
click_button "Vote Answer C"
expect(page).to have_button("You have voted Answer C")
expect(page).to have_button("Vote Answer B", disabled: true)
click_button "You have voted Answer A"
expect(page).to have_button("Vote Answer A")
expect(page).to have_button("Vote Answer B")
click_button "You have voted Answer C"
expect(page).to have_button("Vote Answer C")
click_button "Vote Answer B"
expect(page).to have_button("You have voted Answer B")
expect(page).to have_button("Vote Answer A")
expect(page).to have_button("Vote Answer C")
end
end
end