From 5e98c23be5c24b5e5814a8e043a2664d339642ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= Date: Thu, 21 Mar 2019 10:48:25 +0100 Subject: [PATCH] Fix HTML markup We cannot use 'id' html attributes on nested answers because there will be many answers form each question so this would have generated invalid HTML. --- app/views/dashboard/polls/_form.html.erb | 9 ++---- .../polls/_question_answer_fields.html.erb | 2 +- .../dashboard/polls/_question_fields.html.erb | 9 ++---- spec/features/dashboard/polls_spec.rb | 30 +++++++++---------- 4 files changed, 22 insertions(+), 28 deletions(-) diff --git a/app/views/dashboard/polls/_form.html.erb b/app/views/dashboard/polls/_form.html.erb index da0ab6e32..fbdaf9265 100644 --- a/app/views/dashboard/polls/_form.html.erb +++ b/app/views/dashboard/polls/_form.html.erb @@ -25,18 +25,15 @@ -
+
<%= f.fields_for :questions do |question| %> <%= render 'question_fields', f: question %> <% end %> - diff --git a/app/views/dashboard/polls/_question_answer_fields.html.erb b/app/views/dashboard/polls/_question_answer_fields.html.erb index ff41fb479..4f3dfae57 100644 --- a/app/views/dashboard/polls/_question_answer_fields.html.erb +++ b/app/views/dashboard/polls/_question_answer_fields.html.erb @@ -1,4 +1,4 @@ -
+
<%= f.hidden_field :given_order %>
diff --git a/app/views/dashboard/polls/_question_fields.html.erb b/app/views/dashboard/polls/_question_fields.html.erb index 671bfa50e..d24fa511f 100644 --- a/app/views/dashboard/polls/_question_fields.html.erb +++ b/app/views/dashboard/polls/_question_fields.html.erb @@ -12,18 +12,15 @@
-
+
<%= f.fields_for :question_answers do |answer| %> <%= render 'question_answer_fields', f: answer %> <% end %> - diff --git a/spec/features/dashboard/polls_spec.rb b/spec/features/dashboard/polls_spec.rb index 052766c16..add203101 100644 --- a/spec/features/dashboard/polls_spec.rb +++ b/spec/features/dashboard/polls_spec.rb @@ -104,51 +104,51 @@ feature 'Polls' do end end - scenario 'Edit poll should allow to remove questions', :js do + scenario "Edit poll should allow to remove questions", :js do poll = create(:poll, :incoming, related: proposal) - question1 = create(:poll_question, poll: poll) - question2 = create(:poll_question, poll: poll) + 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' + click_link "Edit survey" end - within "#questions" do + within ".js-questions" do expect(page).to have_css ".nested-fields", count: 2 within first(".nested-fields") do - find('a.delete').click + find("a.delete").click end expect(page).to have_css ".nested-fields", count: 1 end - click_button 'Update poll' + 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 + scenario "Edit poll should allow to remove answers", :js do poll = create(:poll, :incoming, related: proposal) question = create(:poll_question, poll: poll) - answer1 = create(:poll_question_answer, question: question) - answer2 = create(:poll_question_answer, question: question) + 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' + click_link "Edit survey" end - within "#questions #answers" do + within ".js-questions .js-answers" do expect(page).to have_css ".nested-fields", count: 2 within first(".nested-fields") do - find('a.delete').click + find("a.delete").click end expect(page).to have_css ".nested-fields", count: 1 end - click_button 'Update poll' + click_button "Update poll" visit edit_proposal_dashboard_poll_path(proposal, poll) - within "#questions #answers" do + within ".js-questions .js-answers" do expect(page).to have_css ".nested-fields", count: 1 end end