Don't allow to modify questions for started polls
Adding, modifiying, and/or deleting questions for an already started poll is far away from being democratic and can lead to unwanted side effects like missing votes in the results or stats. So, from now on, only modifiying questions will be possible only if the poll has not started yet.
This commit is contained in:
committed by
Javi Martín
parent
d499a6944e
commit
8a26954bc5
@@ -2,9 +2,9 @@ require "rails_helper"
|
||||
|
||||
describe "Admin poll questions", :admin do
|
||||
scenario "Index" do
|
||||
poll1 = create(:poll)
|
||||
poll2 = create(:poll)
|
||||
poll3 = create(:poll)
|
||||
poll1 = create(:poll, :future)
|
||||
poll2 = create(:poll, :future)
|
||||
poll3 = create(:poll, :future)
|
||||
proposal = create(:proposal)
|
||||
question1 = create(:poll_question, poll: poll1)
|
||||
question2 = create(:poll_question, poll: poll2)
|
||||
@@ -55,25 +55,32 @@ describe "Admin poll questions", :admin do
|
||||
expect(page).to have_content question.author.name
|
||||
end
|
||||
|
||||
scenario "Create" do
|
||||
poll = create(:poll, name: "Movies")
|
||||
title = "Star Wars: Episode IV - A New Hope"
|
||||
describe "Create" do
|
||||
scenario "Is possible for a not started poll" do
|
||||
poll = create(:poll, :future, name: "Movies")
|
||||
|
||||
visit admin_poll_path(poll)
|
||||
click_link "Create question"
|
||||
visit admin_poll_path(poll)
|
||||
click_link "Create question"
|
||||
|
||||
expect(page).to have_content("Create question to poll Movies")
|
||||
expect(page).to have_selector("input[id='poll_question_poll_id'][value='#{poll.id}']",
|
||||
visible: :hidden)
|
||||
fill_in "Question", with: title
|
||||
expect(page).to have_content("Create question to poll Movies")
|
||||
expect(page).to have_selector("input[id='poll_question_poll_id'][value='#{poll.id}']",
|
||||
visible: :hidden)
|
||||
|
||||
click_button "Save"
|
||||
fill_in "Question", with: "Star Wars: Episode IV - A New Hope"
|
||||
click_button "Save"
|
||||
|
||||
expect(page).to have_content(title)
|
||||
expect(page).to have_content "Star Wars: Episode IV - A New Hope"
|
||||
end
|
||||
|
||||
scenario "Is not possible for an already started poll" do
|
||||
visit admin_poll_path(create(:poll))
|
||||
|
||||
expect(page).not_to have_link "Create question"
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Create from proposal" do
|
||||
create(:poll, name: "Proposals")
|
||||
create(:poll, :future, name: "Proposals")
|
||||
proposal = create(:proposal)
|
||||
|
||||
visit admin_proposal_path(proposal)
|
||||
@@ -84,7 +91,7 @@ describe "Admin poll questions", :admin do
|
||||
expect(page).to have_current_path(new_admin_question_path, ignore_query: true)
|
||||
expect(page).to have_field("Question", with: proposal.title)
|
||||
|
||||
select "Proposals", from: "poll_question_poll_id"
|
||||
select "Proposals", from: "Poll"
|
||||
|
||||
click_button "Save"
|
||||
|
||||
@@ -92,7 +99,7 @@ describe "Admin poll questions", :admin do
|
||||
end
|
||||
|
||||
scenario "Create from successful proposal" do
|
||||
create(:poll, name: "Proposals")
|
||||
create(:poll, :future, name: "Proposals")
|
||||
proposal = create(:proposal, :successful)
|
||||
|
||||
visit admin_proposal_path(proposal)
|
||||
@@ -103,7 +110,7 @@ describe "Admin poll questions", :admin do
|
||||
expect(page).to have_current_path(new_admin_question_path, ignore_query: true)
|
||||
expect(page).to have_field("Question", with: proposal.title)
|
||||
|
||||
select "Proposals", from: "poll_question_poll_id"
|
||||
select "Proposals", from: "Poll"
|
||||
|
||||
click_button "Save"
|
||||
|
||||
@@ -115,29 +122,29 @@ describe "Admin poll questions", :admin do
|
||||
end
|
||||
|
||||
scenario "Update" do
|
||||
poll = create(:poll)
|
||||
question1 = create(:poll_question, poll: poll)
|
||||
poll = create(:poll, :future)
|
||||
question = create(:poll_question, poll: poll)
|
||||
old_title = question.title
|
||||
new_title = "Vegetables are great and everyone should have one"
|
||||
|
||||
visit admin_poll_path(poll)
|
||||
|
||||
within("#poll_question_#{question1.id}") do
|
||||
within("#poll_question_#{question.id}") do
|
||||
click_link "Edit"
|
||||
end
|
||||
|
||||
expect(page).to have_link "Go back", href: admin_poll_path(poll)
|
||||
old_title = question1.title
|
||||
new_title = "Potatoes are great and everyone should have one"
|
||||
fill_in "Question", with: new_title
|
||||
|
||||
click_button "Save"
|
||||
|
||||
expect(page).to have_content "Changes saved"
|
||||
expect(page).to have_content new_title
|
||||
expect(page).not_to have_content(old_title)
|
||||
expect(page).not_to have_content old_title
|
||||
end
|
||||
|
||||
scenario "Destroy" do
|
||||
poll = create(:poll)
|
||||
poll = create(:poll, :future)
|
||||
question1 = create(:poll_question, poll: poll)
|
||||
question2 = create(:poll_question, poll: poll)
|
||||
|
||||
@@ -156,7 +163,7 @@ describe "Admin poll questions", :admin do
|
||||
|
||||
context "Poll select box" do
|
||||
scenario "translates the poll name in options" do
|
||||
poll = create(:poll, name_en: "Name in English", name_es: "Nombre en Español")
|
||||
poll = create(:poll, :future, name_en: "Name in English", name_es: "Nombre en Español")
|
||||
proposal = create(:proposal)
|
||||
|
||||
visit admin_proposal_path(proposal)
|
||||
@@ -172,7 +179,7 @@ describe "Admin poll questions", :admin do
|
||||
|
||||
scenario "uses fallback if name is not translated to current locale",
|
||||
if: Globalize.fallbacks(:fr).reject { |locale| locale.match(/fr/) }.first == :es do
|
||||
poll = create(:poll, name_en: "Name in English", name_es: "Nombre en Español")
|
||||
poll = create(:poll, :future, name_en: "Name in English", name_es: "Nombre en Español")
|
||||
proposal = create(:proposal)
|
||||
|
||||
visit admin_proposal_path(proposal)
|
||||
|
||||
Reference in New Issue
Block a user