<%= link_to_add_association t("dashboard.polls.question_fields.add_answer"),
f, :question_answers, class: "button hollow" %>
diff --git a/db/dev_seeds/polls.rb b/db/dev_seeds/polls.rb
index a7884d570..1026cb805 100644
--- a/db/dev_seeds/polls.rb
+++ b/db/dev_seeds/polls.rb
@@ -56,11 +56,12 @@ section "Creating Poll Questions & Answers" do
end
end
question.save!
- Faker::Lorem.words((2..4).to_a.sample).each do |title|
+ Faker::Lorem.words((2..4).to_a.sample).each_with_index do |title, index|
description = "
#{Faker::Lorem.paragraphs.join('
')}
"
answer = Poll::Question::Answer.new(question: question,
title: title.capitalize,
- description: description)
+ description: description,
+ given_order: index + 1)
I18n.available_locales.map do |locale|
Globalize.with_locale(locale) do
answer.title = "#{title} (#{locale})"
@@ -200,20 +201,7 @@ section "Creating Poll Questions from Proposals" do
3.times do
proposal = Proposal.all.sample
poll = Poll.current.first
- question = Poll::Question.create(poll: poll)
- Faker::Lorem.words((2..4).to_a.sample).each do |title|
- description = "
#{Faker::ChuckNorris.fact}
"
- answer = Poll::Question::Answer.new(question: question,
- title: title.capitalize,
- description: description)
- I18n.available_locales.map do |locale|
- Globalize.with_locale(locale) do
- answer.title = "#{title} (#{locale})"
- answer.description = "#{description} (#{locale})"
- end
- end
- answer.save!
- end
+ question = Poll::Question.new(poll: poll)
question.copy_attributes_from_proposal(proposal)
title = question.title
I18n.available_locales.map do |locale|
@@ -222,6 +210,20 @@ section "Creating Poll Questions from Proposals" do
end
end
question.save!
+ Faker::Lorem.words((2..4).to_a.sample).each_with_index do |title, index|
+ description = "
#{Faker::ChuckNorris.fact}
"
+ answer = Poll::Question::Answer.new(question: question,
+ title: title.capitalize,
+ description: description,
+ given_order: index + 1)
+ I18n.available_locales.map do |locale|
+ Globalize.with_locale(locale) do
+ answer.title = "#{title} (#{locale})"
+ answer.description = "#{description} (#{locale})"
+ end
+ end
+ answer.save!
+ end
end
end
@@ -229,20 +231,7 @@ section "Creating Successful Proposals" do
10.times do
proposal = Proposal.all.sample
poll = Poll.current.first
- question = Poll::Question.create(poll: poll)
- Faker::Lorem.words((2..4).to_a.sample).each do |title|
- description = "
#{Faker::ChuckNorris.fact}
"
- answer = Poll::Question::Answer.new(question: question,
- title: title.capitalize,
- description: description)
- I18n.available_locales.map do |locale|
- Globalize.with_locale(locale) do
- answer.title = "#{title} (#{locale})"
- answer.description = "#{description} (#{locale})"
- end
- end
- answer.save!
- end
+ question = Poll::Question.new(poll: poll)
question.copy_attributes_from_proposal(proposal)
title = question.title
I18n.available_locales.map do |locale|
@@ -251,5 +240,19 @@ section "Creating Successful Proposals" do
end
end
question.save!
+ Faker::Lorem.words((2..4).to_a.sample).each_with_index do |title, index|
+ description = "
#{Faker::ChuckNorris.fact}
"
+ answer = Poll::Question::Answer.new(question: question,
+ title: title.capitalize,
+ description: description,
+ given_order: index + 1)
+ I18n.available_locales.map do |locale|
+ Globalize.with_locale(locale) do
+ answer.title = "#{title} (#{locale})"
+ answer.description = "#{description} (#{locale})"
+ end
+ end
+ answer.save!
+ end
end
end
diff --git a/spec/factories/polls.rb b/spec/factories/polls.rb
index 648a84afa..88e3b51aa 100644
--- a/spec/factories/polls.rb
+++ b/spec/factories/polls.rb
@@ -47,6 +47,7 @@ FactoryBot.define do
association :question, factory: :poll_question
sequence(:title) { |n| "Answer title #{n}" }
sequence(:description) { |n| "Answer description #{n}" }
+ sequence(:given_order) { |n| n }
end
factory :poll_answer_video, class: 'Poll::Question::Answer::Video' do
diff --git a/spec/features/admin/poll/questions/answers/answers_spec.rb b/spec/features/admin/poll/questions/answers/answers_spec.rb
index dbcf8cf5c..36185743c 100644
--- a/spec/features/admin/poll/questions/answers/answers_spec.rb
+++ b/spec/features/admin/poll/questions/answers/answers_spec.rb
@@ -65,7 +65,7 @@ feature 'Answers' do
expect(page).to have_content(new_title)
expect(page).not_to have_content(old_title)
- expect(page.body.index(new_title)).to be < page.body.index(answer2.title)
+ expect(answer2.title).to appear_before(new_title)
end
end
diff --git a/spec/features/dashboard/polls_spec.rb b/spec/features/dashboard/polls_spec.rb
index 2eafa6652..add203101 100644
--- a/spec/features/dashboard/polls_spec.rb
+++ b/spec/features/dashboard/polls_spec.rb
@@ -52,7 +52,7 @@ feature 'Polls' do
scenario 'Edit poll is allowed for upcoming polls' do
poll = create(:poll, :incoming, related: proposal)
-
+
visit proposal_dashboard_polls_path(proposal)
within "div#poll_#{poll.id}" do
@@ -68,7 +68,7 @@ feature 'Polls' do
scenario 'Edit poll redirects back when invalid data', js: true do
poll = create(:poll, :incoming, related: proposal)
-
+
visit proposal_dashboard_polls_path(proposal)
within "div#poll_#{poll.id}" do
@@ -86,7 +86,7 @@ feature 'Polls' do
scenario 'Edit poll is not allowed for current polls' do
poll = create(:poll, :current, related: proposal)
-
+
visit proposal_dashboard_polls_path(proposal)
within "div#poll_#{poll.id}" do
@@ -96,7 +96,7 @@ feature 'Polls' do
scenario 'Edit poll is not allowed for expired polls' do
poll = create(:poll, :expired, related: proposal)
-
+
visit proposal_dashboard_polls_path(proposal)
within "div#poll_#{poll.id}" do
@@ -104,9 +104,58 @@ feature 'Polls' do
end
end
+ scenario "Edit poll should allow to remove questions", :js do
+ poll = create(:poll, :incoming, related: proposal)
+ create(:poll_question, poll: poll)
+ create(:poll_question, poll: poll)
+ visit proposal_dashboard_polls_path(proposal)
+ within "div#poll_#{poll.id}" do
+ click_link "Edit survey"
+ end
+
+ within ".js-questions" do
+ expect(page).to have_css ".nested-fields", count: 2
+ within first(".nested-fields") do
+ find("a.delete").click
+ end
+ expect(page).to have_css ".nested-fields", count: 1
+ end
+
+ click_button "Update poll"
+ visit edit_proposal_dashboard_poll_path(proposal, poll)
+
+ expect(page).to have_css ".nested-fields", count: 1
+ end
+
+ scenario "Edit poll should allow to remove answers", :js do
+ poll = create(:poll, :incoming, related: proposal)
+ question = create(:poll_question, poll: poll)
+ create(:poll_question_answer, question: question)
+ create(:poll_question_answer, question: question)
+ visit proposal_dashboard_polls_path(proposal)
+ within "div#poll_#{poll.id}" do
+ click_link "Edit survey"
+ end
+
+ within ".js-questions .js-answers" do
+ expect(page).to have_css ".nested-fields", count: 2
+ within first(".nested-fields") do
+ find("a.delete").click
+ end
+ expect(page).to have_css ".nested-fields", count: 1
+ end
+
+ click_button "Update poll"
+ visit edit_proposal_dashboard_poll_path(proposal, poll)
+
+ within ".js-questions .js-answers" do
+ expect(page).to have_css ".nested-fields", count: 1
+ end
+ end
+
scenario 'View results not available for upcoming polls' do
poll = create(:poll, :incoming, related: proposal)
-
+
visit proposal_dashboard_polls_path(proposal)
within "div#poll_#{poll.id}" do
@@ -116,7 +165,7 @@ feature 'Polls' do
scenario 'View results available for current polls' do
poll = create(:poll, :current, related: proposal)
-
+
visit proposal_dashboard_polls_path(proposal)
within "div#poll_#{poll.id}" do
@@ -126,7 +175,7 @@ feature 'Polls' do
scenario 'View results available for expired polls' do
poll = create(:poll, :expired, related: proposal)
-
+
visit proposal_dashboard_polls_path(proposal)
within "div#poll_#{poll.id}" do
@@ -136,7 +185,7 @@ feature 'Polls' do
scenario 'View results redirects to results in public zone', js: true do
poll = create(:poll, :expired, related: proposal)
-
+
visit proposal_dashboard_polls_path(proposal)
within "div#poll_#{poll.id}" do
@@ -150,7 +199,7 @@ feature 'Polls' do
scenario 'Poll card' do
poll = create(:poll, :expired, related: proposal)
-
+
visit proposal_dashboard_polls_path(proposal)
within "div#poll_#{poll.id}" do
diff --git a/spec/features/officing/results_spec.rb b/spec/features/officing/results_spec.rb
index 376629314..e46bef692 100644
--- a/spec/features/officing/results_spec.rb
+++ b/spec/features/officing/results_spec.rb
@@ -8,11 +8,11 @@ feature 'Officing Results', :with_frozen_time do
@poll = @officer_assignment.booth_assignment.poll
@poll.update(ends_at: 1.day.ago)
@question_1 = create(:poll_question, poll: @poll)
- create(:poll_question_answer, title: 'Yes', question: @question_1)
- create(:poll_question_answer, title: 'No', question: @question_1)
+ create(:poll_question_answer, title: "Yes", question: @question_1, given_order: 1)
+ create(:poll_question_answer, title: "No", question: @question_1, given_order: 2)
@question_2 = create(:poll_question, poll: @poll)
- create(:poll_question_answer, title: 'Today', question: @question_2)
- create(:poll_question_answer, title: 'Tomorrow', question: @question_2)
+ create(:poll_question_answer, title: "Today", question: @question_2, given_order: 1)
+ create(:poll_question_answer, title: "Tomorrow", question: @question_2, given_order: 2)
login_as(@poll_officer.user)
end
diff --git a/spec/features/polls/answers_spec.rb b/spec/features/polls/answers_spec.rb
index 6daffc0eb..8e5bb785e 100644
--- a/spec/features/polls/answers_spec.rb
+++ b/spec/features/polls/answers_spec.rb
@@ -16,7 +16,7 @@ feature 'Answers' do
visit admin_question_path(question)
expect(page).to have_css(".poll_question_answer", count: 2)
- expect(page.body.index(answer1.title)).to be < page.body.index(answer2.title)
+ expect(answer2.title).to appear_before(answer1.title)
within("#poll_question_answer_#{answer1.id}") do
expect(page).to have_content answer1.title
diff --git a/spec/features/polls/polls_spec.rb b/spec/features/polls/polls_spec.rb
index 64d92eb14..69fbd68e5 100644
--- a/spec/features/polls/polls_spec.rb
+++ b/spec/features/polls/polls_spec.rb
@@ -28,7 +28,7 @@ feature 'Polls' do
scenario "Proposal polls won't be listed" do
proposal = create(:proposal)
- _poll = create(:poll, related: proposal)
+ _poll = create(:poll, related: proposal)
visit polls_path
expect(page).to have_content('There are no open votings')
@@ -164,7 +164,7 @@ feature 'Polls' do
visit poll_path(poll)
within("div#poll_question_#{question.id}") do
- expect(page.body.index(answer1.title)).to be < page.body.index(answer2.title)
+ expect(answer2.title).to appear_before(answer1.title)
end
end
@@ -176,7 +176,7 @@ feature 'Polls' do
visit poll_path(poll)
within('div.poll-more-info-answers') do
- expect(page.body.index(answer1.title)).to be < page.body.index(answer2.title)
+ expect(answer2.title).to appear_before(answer1.title)
end
end