Add support for open-ended questions in admin section
Introduce a new "open" votation type for poll questions in the admin interface. This type allows open answers provided by the user.
This commit is contained in:
@@ -94,6 +94,12 @@ FactoryBot.define do
|
||||
create(:votation_type_multiple, questionable: question, max_votes: evaluator.max_votes)
|
||||
end
|
||||
end
|
||||
|
||||
factory :poll_question_open do
|
||||
after(:create) do |question|
|
||||
create(:votation_type_open, questionable: question)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
factory :poll_question_option, class: "Poll::Question::Option" do
|
||||
|
||||
@@ -9,6 +9,10 @@ FactoryBot.define do
|
||||
max_votes { 3 }
|
||||
end
|
||||
|
||||
factory :votation_type_open do
|
||||
vote_type { "open" }
|
||||
end
|
||||
|
||||
questionable factory: :poll_question
|
||||
end
|
||||
end
|
||||
|
||||
@@ -30,6 +30,13 @@ describe Poll::Answer do
|
||||
expect(answer).not_to be_valid
|
||||
end
|
||||
|
||||
it "is not valid without an answer when question is open-ended" do
|
||||
answer.question = create(:poll_question_open)
|
||||
answer.answer = nil
|
||||
|
||||
expect(answer).not_to be_valid
|
||||
end
|
||||
|
||||
it "is not valid if there's already an answer to that question" do
|
||||
author = create(:user)
|
||||
question = create(:poll_question, :yes_no)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe VotationType do
|
||||
let(:vote_types) { %i[votation_type_unique votation_type_multiple] }
|
||||
let(:vote_types) { %i[votation_type_unique votation_type_multiple votation_type_open] }
|
||||
let(:votation_type) { build(vote_types.sample) }
|
||||
|
||||
it "is valid" do
|
||||
@@ -27,6 +27,10 @@ describe VotationType do
|
||||
|
||||
expect(votation_type).to be_valid
|
||||
|
||||
votation_type.vote_type = "open"
|
||||
|
||||
expect(votation_type).to be_valid
|
||||
|
||||
votation_type.vote_type = "multiple"
|
||||
|
||||
expect(votation_type).not_to be_valid
|
||||
|
||||
@@ -81,6 +81,8 @@ describe "Admin poll questions", :admin do
|
||||
expect(page).to have_content "It's only possible to answer one time to the question."
|
||||
expect(page).not_to have_content "Allows to choose multiple answers."
|
||||
expect(page).not_to have_field "Maximum number of votes"
|
||||
expect(page).not_to have_content "Open-ended question that allows users to provide " \
|
||||
"a single answer in their own words."
|
||||
|
||||
click_button "Save"
|
||||
|
||||
@@ -94,6 +96,8 @@ describe "Admin poll questions", :admin do
|
||||
|
||||
expect(page).not_to have_content "It's only possible to answer one time to the question."
|
||||
expect(page).to have_content "Allows to choose multiple answers."
|
||||
expect(page).not_to have_content "Open-ended question that allows users to provide " \
|
||||
"a single answer in their own words."
|
||||
|
||||
fill_in "Maximum number of votes", with: 6
|
||||
click_button "Save"
|
||||
@@ -101,6 +105,21 @@ describe "Admin poll questions", :admin do
|
||||
expect(page).to have_content "Question with multiple answers"
|
||||
expect(page).to have_content "Multiple answers"
|
||||
end
|
||||
|
||||
scenario "Open-ended" do
|
||||
fill_in "Question", with: "What do you want?"
|
||||
select "Open-ended", from: "Votation type"
|
||||
|
||||
expect(page).not_to have_content "Allows to choose multiple answers."
|
||||
expect(page).not_to have_field "Maximum number of votes"
|
||||
expect(page).to have_content "Open-ended question that allows users to provide " \
|
||||
"a single answer in their own words."
|
||||
|
||||
click_button "Save"
|
||||
|
||||
expect(page).to have_content "What do you want?"
|
||||
expect(page).to have_content "Open-ended"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -143,7 +162,7 @@ describe "Admin poll questions", :admin do
|
||||
|
||||
scenario "Update" do
|
||||
poll = create(:poll, :future)
|
||||
question = create(:poll_question, poll: poll)
|
||||
question = create(:poll_question_open, poll: poll)
|
||||
old_title = question.title
|
||||
new_title = "Vegetables are great and everyone should have one"
|
||||
|
||||
@@ -154,6 +173,12 @@ describe "Admin poll questions", :admin do
|
||||
end
|
||||
|
||||
expect(page).to have_link "Go back", href: admin_poll_path(poll)
|
||||
expect(page).to have_select "Votation type", selected: "Open-ended"
|
||||
expect(page).not_to have_content "Allows to choose multiple answers."
|
||||
expect(page).not_to have_field "Maximum number of votes"
|
||||
expect(page).to have_content "Open-ended question that allows users to provide " \
|
||||
"a single answer in their own words."
|
||||
|
||||
fill_in "Question", with: new_title
|
||||
|
||||
click_button "Save"
|
||||
|
||||
Reference in New Issue
Block a user